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

 

NAME

dbex_compile, dbex_eval, dbex_free, dbex_evalstr - database expression evaluation

SYNOPSIS

#include "db.h"

int dbex_compile(Dbptr db, char *s,
                 Expression **expression, int type)

int dbex_eval(Dbptr db, Expression *expression,
                 int setflag, void *result)

int dbex_free(Expression *expression)

int dbex_evalstr(Dbptr db, char *s, int type,
                 void *value)

DESCRIPTION

These routines implement a small calculator for expressions involving database pointers.

dbex_compile takes as input a database pointer, a character string representing an expression, and a flag type which indicates the expected type of the result; results are coerced to this type. type may take the values dbBOOLEAN, dbINTEGER, dbREAL, dbTIME, dbYEARDAY, or dbSTRING. If type is zero, no conversion/coercion is performed, and dbex_eval returns whatever type is implied by the expression itself.

dbex_compile returns an Expression, which may be evaluated with dbex_eval. The database pointer given to dbex_compile is used to resolve field references in the expression. The database pointer given to dbex_eval is used to specify the record number. If setflag is non-zero, the calculator may assign to fields, that is, change the value of a field in the database.

dbex_free frees an expression (the passed pointer may be null).

dbex_evalstr takes a database pointer and a string, compiles and evaluates the character string as an expression, frees the compiled expression, and returns the result. The return type may be coerced by setting type to dbBOOLEAN, dbINTEGER, dbREAL, dbTIME, dbYEARDAY, or dbSTRING. If type is zero, no conversion/coercion is performed, and dbex_eval returns whatever type is implied by the expression itself.

Please refer to dbexpressions(5) or the Datascope tutorial for a description of the terms and operations which the calculator recognizes.

EXAMPLE

Examine dbcalc.c or dbsubset.c for a simple example of the c interface to the calculator.

RETURN VALUES

When successful, dbex_compile returns a positive number (dbBOOLEAN, dbINTEGER, dbREAL, dbTIME, dbYEARDAY, or dbSTRING) indicating the type of the returned value. -1 is returned in the event of failure, and the returned compiled expression is null. Use clear_register(3) to print error messages from dbex_compile.

dbex_eval returns a boolean integer which is positive, non-zero if the expression evaluates to true, zero if it evaluates to false. If the evaluation fails, dbINVALID (negative value) is returned.

dbex_evalstr returns a positive datatype (dbBOOLEAN, dbINTEGER, dbREAL, dbTIME, dbYEARDAY or dbSTRING) for success, and a negative value if compilation or evaluation of the string failed.

When dbex_eval or dbex_evalstr return a dbSTRING value, the returned string is in space allocated with malloc, and should be freed by the caller.

dbex_free always returns 0.

LIBRARY

$(DBLIBS)

SEE ALSO

dbintro(3)
dbexpressions(5)
clear_register(3)

BUGS AND CAVEATS

When the return value from dbex_eval is a (pointer to a) string, the caller must free it -- e.g., free(value.t).

AUTHOR

Daniel Quinlan
Printer icon