mirror of
https://github.com/owntone/owntone-server.git
synced 2025-03-20 12:34:18 -04:00
Fixes for not, add startswith and endswith operators
This commit is contained in:
parent
a8e9e7bfd6
commit
24f40d7956
@ -132,7 +132,9 @@ typedef struct tag_sp_node {
|
|||||||
#define T_YEAR 0x0019
|
#define T_YEAR 0x0019
|
||||||
#define T_DATE 0x001a
|
#define T_DATE 0x001a
|
||||||
#define T_NOT 0x001b
|
#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_EOF 0x00fd
|
||||||
#define T_BOF 0x00fe
|
#define T_BOF 0x00fe
|
||||||
@ -166,7 +168,9 @@ char *sp_token_descr[] = {
|
|||||||
"month(s)",
|
"month(s)",
|
||||||
"year(s)",
|
"year(s)",
|
||||||
"date",
|
"date",
|
||||||
"not"
|
"not",
|
||||||
|
"like",
|
||||||
|
"like"
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct tag_fieldlookup {
|
typedef struct tag_fieldlookup {
|
||||||
@ -231,6 +235,8 @@ FIELDLOOKUP sp_fields[] = {
|
|||||||
{ T_YEAR, "years" },
|
{ T_YEAR, "years" },
|
||||||
{ T_YEAR, "year" },
|
{ T_YEAR, "year" },
|
||||||
{ T_NOT, "not" },
|
{ T_NOT, "not" },
|
||||||
|
{ T_STARTSWITH, "startswith" },
|
||||||
|
{ T_ENDSWITH, "endswith" },
|
||||||
|
|
||||||
/* end */
|
/* end */
|
||||||
{ 0, NULL },
|
{ 0, NULL },
|
||||||
@ -510,6 +516,7 @@ int sp_scan(PARSETREE tree) {
|
|||||||
|
|
||||||
/* check for numberic? */
|
/* check for numberic? */
|
||||||
if(tree->token.token_id == T_STRING &&
|
if(tree->token.token_id == T_STRING &&
|
||||||
|
(!tree->in_string) &&
|
||||||
sp_isnumber(tree->token.data.cvalue)) {
|
sp_isnumber(tree->token.data.cvalue)) {
|
||||||
/* woops! */
|
/* woops! */
|
||||||
numval = atoi(tree->token.data.cvalue);
|
numval = atoi(tree->token.data.cvalue);
|
||||||
@ -519,6 +526,7 @@ int sp_scan(PARSETREE tree) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(tree->token.token_id == T_STRING &&
|
if(tree->token.token_id == T_STRING &&
|
||||||
|
(!tree->in_string) &&
|
||||||
(tval=sp_isdate(tree->token.data.cvalue))) {
|
(tval=sp_isdate(tree->token.data.cvalue))) {
|
||||||
free(tree->token.data.cvalue);
|
free(tree->token.data.cvalue);
|
||||||
tree->token.data.tvalue = tval;
|
tree->token.data.tvalue = tval;
|
||||||
@ -806,6 +814,8 @@ SP_NODE *sp_parse_criterion(PARSETREE tree) {
|
|||||||
switch(tree->token.token_id) {
|
switch(tree->token.token_id) {
|
||||||
case T_EQUAL:
|
case T_EQUAL:
|
||||||
case T_INCLUDES:
|
case T_INCLUDES:
|
||||||
|
case T_STARTSWITH:
|
||||||
|
case T_ENDSWITH:
|
||||||
pnew->op=tree->token.token_id;
|
pnew->op=tree->token.token_id;
|
||||||
pnew->op_type = SP_OPTYPE_STRING;
|
pnew->op_type = SP_OPTYPE_STRING;
|
||||||
result = 1;
|
result = 1;
|
||||||
@ -1192,6 +1202,9 @@ int sp_node_size(SP_NODE *node) {
|
|||||||
if(node->op == T_INCLUDES) {
|
if(node->op == T_INCLUDES) {
|
||||||
size += 2; /* extra %'s */
|
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)) {
|
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,")");
|
strcat(string,")");
|
||||||
} else {
|
} else {
|
||||||
strcat(string,"(");
|
strcat(string,"(");
|
||||||
strcat(string,node->left.field);
|
|
||||||
strcat(string," ");
|
|
||||||
if(node->not_flag) {
|
if(node->not_flag) {
|
||||||
strcat(string,"not ");
|
strcat(string,"not ");
|
||||||
}
|
}
|
||||||
|
strcat(string,node->left.field);
|
||||||
|
strcat(string," ");
|
||||||
strcat(string,sp_token_descr[node->op & 0x0FFF]);
|
strcat(string,sp_token_descr[node->op & 0x0FFF]);
|
||||||
strcat(string," ");
|
strcat(string," ");
|
||||||
if(node->op_type == SP_OPTYPE_STRING) {
|
if(node->op_type == SP_OPTYPE_STRING) {
|
||||||
strcat(string,"'");
|
strcat(string,"'");
|
||||||
if(node->op == T_INCLUDES)
|
if((node->op == T_INCLUDES) || (node->op == T_ENDSWITH))
|
||||||
strcat(string,"%");
|
strcat(string,"%");
|
||||||
strcat(string,node->right.cvalue);
|
strcat(string,node->right.cvalue);
|
||||||
if(node->op == T_INCLUDES)
|
if((node->op == T_INCLUDES) || (node->op == T_STARTSWITH))
|
||||||
strcat(string,"%");
|
strcat(string,"%");
|
||||||
strcat(string,"'");
|
strcat(string,"'");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user