Fixes for not, add startswith and endswith operators

This commit is contained in:
Ron Pedde 2005-12-13 20:42:03 +00:00
parent a8e9e7bfd6
commit 24f40d7956

View File

@ -132,7 +132,9 @@ typedef struct tag_sp_node {
#define T_YEAR 0x0019
#define T_DATE 0x001a
#define T_NOT 0x001b
#define T_LAST 0x001c
#define T_STARTSWITH 0x001c
#define T_ENDSWITH 0x001d
#define T_LAST 0x001e
#define T_EOF 0x00fd
#define T_BOF 0x00fe
@ -166,7 +168,9 @@ char *sp_token_descr[] = {
"month(s)",
"year(s)",
"date",
"not"
"not",
"like",
"like"
};
typedef struct tag_fieldlookup {
@ -231,6 +235,8 @@ FIELDLOOKUP sp_fields[] = {
{ T_YEAR, "years" },
{ T_YEAR, "year" },
{ T_NOT, "not" },
{ T_STARTSWITH, "startswith" },
{ T_ENDSWITH, "endswith" },
/* end */
{ 0, NULL },
@ -510,6 +516,7 @@ int sp_scan(PARSETREE tree) {
/* check for numberic? */
if(tree->token.token_id == T_STRING &&
(!tree->in_string) &&
sp_isnumber(tree->token.data.cvalue)) {
/* woops! */
numval = atoi(tree->token.data.cvalue);
@ -519,6 +526,7 @@ int sp_scan(PARSETREE tree) {
}
if(tree->token.token_id == T_STRING &&
(!tree->in_string) &&
(tval=sp_isdate(tree->token.data.cvalue))) {
free(tree->token.data.cvalue);
tree->token.data.tvalue = tval;
@ -806,6 +814,8 @@ SP_NODE *sp_parse_criterion(PARSETREE tree) {
switch(tree->token.token_id) {
case T_EQUAL:
case T_INCLUDES:
case T_STARTSWITH:
case T_ENDSWITH:
pnew->op=tree->token.token_id;
pnew->op_type = SP_OPTYPE_STRING;
result = 1;
@ -1192,6 +1202,9 @@ int sp_node_size(SP_NODE *node) {
if(node->op == T_INCLUDES) {
size += 2; /* extra %'s */
}
if((node->op == T_STARTSWITH)||(node->op == T_ENDSWITH)) {
size += 1;
}
}
if((node->op_type == SP_OPTYPE_INT) || (node->op_type == SP_OPTYPE_DATE)) {
@ -1224,19 +1237,19 @@ void sp_serialize_sql(SP_NODE *node, char *string) {
strcat(string,")");
} else {
strcat(string,"(");
strcat(string,node->left.field);
strcat(string," ");
if(node->not_flag) {
strcat(string,"not ");
}
strcat(string,node->left.field);
strcat(string," ");
strcat(string,sp_token_descr[node->op & 0x0FFF]);
strcat(string," ");
if(node->op_type == SP_OPTYPE_STRING) {
strcat(string,"'");
if(node->op == T_INCLUDES)
if((node->op == T_INCLUDES) || (node->op == T_ENDSWITH))
strcat(string,"%");
strcat(string,node->right.cvalue);
if(node->op == T_INCLUDES)
if((node->op == T_INCLUDES) || (node->op == T_STARTSWITH))
strcat(string,"%");
strcat(string,"'");
}