#include "db.h" long dbfind(Dbptr db, char *string, int flags, Hook **hook)
The string may be either a valid Datascope expression, or a plain string. dbfind decides which by inspecting the string. If the first character is '/', then the remainder of the string is a regular expression. Otherwise, if the string compiles properly, it is a Datascope expression, otherwise it is a regular expression.
The hook saves some intermediate values, in case the caller makes multiple calls with the same string. The hook must be initialized to zero, and should be freed with free_hook(3) when done. Alternatively, the argument may be null, and no intermediate compilations are saved. dbfind does recognize when the string changes, so it's not necessary to free the hook whenever that happens.
nrecords = dbopen_table (table, "r", &db); db.record = 0 ; . . flags = 0 ; result = dbfind (db, string, flags, 0 ); switch ( result ) { case -1: complain ( 0, "'%s' didn't compile", string ) ; break; case -2: complain ( 0, "searched to the end" ) ; break ; case -3: complain ( 0, "searched to the beginning" ) ; break ; default: elog_notify(0, "Found record #%d", result ) ; break ; }
dbsubset(3)