• Antelope Release 5.10 Linux CentOS release 7.6.1810 (Core) 3.10.0 2020-05-12

 

NAME

dbfind - search for matching record in table

SYNOPSIS

#include "db.h"

long dbfind(Dbptr db, char *string, int flags,
                 Hook **hook)

DESCRIPTION

dbfind searches a table or view for a record which matches the input string, returning the record number for the first matching row. The view to search and starting record are specified by db. If flags has bit 0 set, the search is downward, otherwise it is toward increasing record number. The search commences after the record specified in db; to search from the beginning (including the first record), set the record number < 0. To search from the end, set the record number >= the number of records.

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.

EXAMPLE



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 ;
    }

RETURN VALUES

dbfind returns a record number >= zero when successful, -1 when some (compilation) error occurred, -2 when the search failed by going past the last record, and -3 when the search failed by going past the first record.

LIBRARY

$(DBLIBS)

SEE ALSO

dbsubset(3)

AUTHOR

Daniel Quinlan
Printer icon