Databases Reference
In-Depth Information
Then we initialize the lookups structure and call the magic function that will analyze
the WHERE clause and store the constants in this structure:
bzero((char*) &lookups, sizeof(lookups));
if (calc_lookup_values_from_cond(thd, cond,
tables, &lookups))
return 0;
The calc_lookup_values_from_cond() returns 1 when a field value is compared
to NULL . As our field cannot be NULL , we can return right away—nothing that we can
put in the table will satisfy the WHERE condition.
Otherwise we try to fill the table:
for (num = 0, ptr = output; *ptr; ptr++)
{
if (lookups.value1.str &&
my_strnncoll(cs, (const uchar*)*ptr, strlen(*ptr),
(const uchar*)lookups.value1.str,
lookups.value1.length))
continue;
If the WHERE clause has given us a value that we can filter on—that is, if the str
pointer of the lookups.value1 is not 0—we compare it with the word that we
want to put into the row. For comparison we use the my_strnncoll() function that
compares two strings using the collation, passed as the first argument ( system_
charset_info is utf8_general_ci ), and takes both strings and their lengths too
(indeed, the string is not necessarily zero terminated; after all, one can write WHERE
field='a\0b' ).
If the value matches the word or if there is no value in the lookups.value1 at all, we
store a new row in the table:
table->field[0]->store(++num);
table->field[1]->store(*ptr, strlen(*ptr), cs);
if (schema_table_store_record(thd, table))
return 1;
}
return 0;
}
 
Search WWH ::




Custom Search