Product Documentation

FairCom ISAM for C

Previous Topic

Next Topic

cndxparse

Creates an expression tree for later evaluation.

Declaration

PTREE cndxparse( pConvMap Schema, pTEXT Names, pTEXT InputText, NINT InputTextSize )

Description

You can use the FairCom DB expression parser/analyzer to evaluate expressions. For a complete sample program, see ctexpr.c in the ctree/source directory.

Where:

  • Schema - DODA
  • Names - List of names of fields
  • InputText - Text of conditional expression
  • InputTextSize - Length of text for conditional expression

Using the FairCom DB expression parser/analyzer involves two steps:

  1. Calling cndxparse() to parse your expression, producing an expression tree the expression analyzer can evaluate. This involves three steps:
    1. Define a DODA structure.
    2. Parse the DODA into a record schema and field name list.
    3. Parse your expression to produce an expression tree.
  2. Calling cndxeval() to evaluate the expression tree using data from a buffer in memory.

Return Values

Returns a PTREE parse tree on success. NULL if error.

Example

#include "ctcndx.h" /* For PTREE type */

/* Define a DODA structure. */

DATOBJ doda[] = {

{"CustomerNumber", 0, CT_INT4U},

{"ZipCode", 4, CT_FSTRING, 9},

{"State", 13, CT_FSTRING, 2},

{"LastName", 15, CT_STRING, 37},

{"FirstName", 52, CT_STRING, 37},

{"Address", 89, CT_STRING, 49},

{"City", 138, CT_STRING, 37}

};


COUNT retval; /* Return code. */

pTEXT schema; /* Record schema. */

pTEXT names; /* Field name list. */

PTREE ptree; /* Expression tree. */

pTEXT expr; /* Expression string. */

/* Parse the DODA into a record schema and field name list. */

if ((retval = ctparsedoda(doda, 7, &schema, &names)) != 0)

printf("Error %d parsing DODA.\n", retval);


/* Parse your expression to produce an expression tree. */

expr = "stricmp(LastName, \"Smith\") == 0

&& CustomerNumber > 10000";

ptree = cndxparse(schema, names, expr, strlen(expr));

if (!ptree)

printf("Error: Unable to parse expression.\n");

else

printf("Successfully parsed expression.\n");

...

if ( ptree )

cndxfree (ptree);

See also

cndxeval, cndxfree, ctparsedoda, cndxrun, getcndxmem, putcndxmem

TOCIndex