From f56884015f581922a390461d46e91aa259151f55 Mon Sep 17 00:00:00 2001 From: Julien BLACHE Date: Tue, 29 Dec 2009 19:10:22 +0100 Subject: [PATCH] Allow empty values in DMAP queries for string fields --- src/DAAP2SQL.g | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/src/DAAP2SQL.g b/src/DAAP2SQL.g index 41850484..19ca75b8 100644 --- a/src/DAAP2SQL.g +++ b/src/DAAP2SQL.g @@ -136,28 +136,18 @@ expr returns [ pANTLR3_STRING result, int valid ] *val = '\0'; val++; - if (*val == '\0') - { - if (op == '!') - DPRINTF(E_LOG, L_DAAP, "Negation found but operator missing in clause '\%s\%c'\n", field, op); - else - DPRINTF(E_LOG, L_DAAP, "No value given in clause '\%s\%c'\n", field, op); - $valid = 0; - goto STR_result_valid_0; /* ABORT */ - } - if (op == '!') { - neg_op = 1; - op = *val; - val++; - if (*val == '\0') { - DPRINTF(E_LOG, L_DAAP, "No value given in clause '\%s!\%c'\n", field, op); + DPRINTF(E_LOG, L_DAAP, "Negation found but operator missing in clause '\%s\%c'\n", field, op); $valid = 0; goto STR_result_valid_0; /* ABORT */ } + + neg_op = 1; + op = *val; + val++; } else neg_op = 0; @@ -171,6 +161,14 @@ expr returns [ pANTLR3_STRING result, int valid ] goto STR_result_valid_0; /* ABORT */ } + /* Empty values OK for string fields, NOK for integer */ + if ((*val == '\0') && (dqfm->as_int)) + { + DPRINTF(E_LOG, L_DAAP, "No value given in clause '\%s\%s\%c'\n", field, (neg_op) ? "!" : "", op); + $valid = 0; + goto STR_result_valid_0; /* ABORT */ + } + $result->append8($result, dqfm->db_col); /* Int field: check integer conversion */ @@ -182,16 +180,16 @@ expr returns [ pANTLR3_STRING result, int valid ] if (((errno == ERANGE) && ((longval == LONG_MAX) || (longval == LONG_MIN))) || ((errno != 0) && (longval == 0))) { - DPRINTF(E_LOG, L_DAAP, "Value '\%s' in clause '\%s\%c\%s' does not convert to an integer type\n", - val, field, op, val); + DPRINTF(E_LOG, L_DAAP, "Value '\%s' in clause '\%s\%s\%c\%s' does not convert to an integer type\n", + val, field, (neg_op) ? "!" : "", op, val); $valid = 0; goto STR_result_valid_0; /* ABORT */ } if (end == (char *)val) { - DPRINTF(E_LOG, L_DAAP, "Value '\%s' in clause '\%s\%c\%s' does not represent an integer value\n", - val, field, op, val); + DPRINTF(E_LOG, L_DAAP, "Value '\%s' in clause '\%s\%s\%c\%s' does not represent an integer value\n", + val, field, (neg_op) ? "!" : "", op, val); $valid = 0; goto STR_result_valid_0; /* ABORT */ }