Process complex qualifications
In the following figure, the am_getnext purpose
function attempts to disqualify source records. It creates rows for
fully qualified source records and for those rows that it cannot disqualify.
Figure 1. Sample am_getnext purpose
function
mi_integer sample_getnext(sd,retrow,retrowid)
MI_AM_SCAN_DESC *sd;
MI_ROW **retrow
mi_integer retrowid;
{
my_data_t *my_data;
MI_ROW_DESC *rd;
MI_AM_TABLE_DESC *td;
MI_AM_QUAL_DESC *qd;
td = mi_scan_table(sd); /* Get table descriptor. */
rd = mi_tab_rowdesc(td); /* Get column data types. */
my_data = (my_data_t *)mi_tab_userdata(td); /* Get pointer to user data.*/
MI_DATUM qdvalue;
/* Evaluate records until one qualifies for return to caller.. */
for (;;)
{
/* Test for and exit if end of data. (more_rows() routine not shown.)*/
if (more_rows(my_data) !=MI_OK)
return MI_NO_MORE_RESULTS;
/* User data contains more rows, so evaluate the next one */
get_results(qd, my_data);
qdvalue = mi_qual_value(qd)
if (qdvalue == MI_VALUE_TRUE)
{
/*Create MI_ROW and return it to the database server. */
*retrow = mi_row_create(...);
return MI_ROWS;
}
else if (qdvalue == MI_VALUE_NOT_EVALUATED)
{
/*Create MI_ROW and return it to the database server. */
*retrow = mi_row_create(...);
if (mi_eval_am_qual(retrow, qd) == MI_VALUE_TRUE)
return MI_ROWS;
}
/* Either get_result() or mi_eval_am_qual() returned MI_VALUE_FALSE. */
mi_init_am_qual(qd); /* Reset qualification descriptor */
my_data->rowptr++;
} /*End loop.*/
}/* End getnext.*/
In the next figure, the get_result() function
loops recursively through the qualification descriptor, looking for
simple qualifications that the access method knows how to evaluate.
It sets results for the simple qualifications and leaves MI_VALUE_NOT_EVALUATED
in the Boolean-operator portions of the qualification descriptor.
Tip: The examples in this topic do not illustrate the code that
the access method uses to execute functions.
Figure 2. Setting results in the
qualification descriptor
... get_result(qd, my_data)
MI_AM_QUAL_DESC *qd;
user_data_t *my_data
{
if (mi_qual_issimple(qd))
{
/* Execute simple, function. (Not shown.) */
/* Test the result that the function returns. */
if (result == MI_TRUE)
{
/* Set result in qualification descriptor.*/
mi_qual_setvalue(qd,MI_VALUE_TRUE);
return; ;
}
else
{
mi_qual_setvalue( qd,MI_VALUE_FALSE);
return;;
}
} /* END: if (mi_qual_issimple(qd)) */
else
{/*Complex qualification (has AND or OR)..Loop until all functions execute.*/
for (i = 0; i < mi_qual_nquals(qd); i++)
get_result(mi_qual_qual(qd, i), my_data)
} /* END: Complex qualification (has AND or OR)*/
return;;