From 3665b7c34fffd76cb3b4aa6756ba477f6ff8075a Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Wed, 23 Apr 2014 01:45:43 -0400 Subject: [PATCH] LP#1311467: fix heading validation in bib editor This patch fixes a regression whereby clicking the validate button in the bib editor would result in no headings getting checked. In the process, it enables 'startwith' to be used as a JSON query operator for all types of predicates, not just the results of transformed values. Signed-off-by: Galen Charlton Signed-off-by: Mike Rylander --- Open-ILS/examples/fm_IDL.xml | 2 ++ Open-ILS/src/c-apps/oils_sql.c | 25 +++++++++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml index adfcd2eb15..f318da84d5 100644 --- a/Open-ILS/examples/fm_IDL.xml +++ b/Open-ILS/examples/fm_IDL.xml @@ -2352,6 +2352,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + + diff --git a/Open-ILS/src/c-apps/oils_sql.c b/Open-ILS/src/c-apps/oils_sql.c index e72bb49530..dac5d8c9d7 100644 --- a/Open-ILS/src/c-apps/oils_sql.c +++ b/Open-ILS/src/c-apps/oils_sql.c @@ -2656,14 +2656,23 @@ static char* searchFunctionPredicate( const char* class_alias, osrfHash* field, if( !val ) return NULL; + const char* right_percent = ""; + const char* real_op = op; + + if( !strcasecmp( op, "startwith") ) { + real_op = "like"; + right_percent = "|| '%'"; + } + growing_buffer* sql_buf = buffer_init( 32 ); buffer_fadd( sql_buf, - "\"%s\".%s %s %s", + "\"%s\".%s %s %s%s", class_alias, osrfHashGet( field, "name" ), - op, - val + real_op, + val, + right_percent ); free( val ); @@ -2899,8 +2908,16 @@ static char* searchSimplePredicate( const char* op, const char* class_alias, op = "IS"; } + const char* right_percent = ""; + const char* real_op = op; + + if( !strcasecmp( op, "startwith") ) { + real_op = "like"; + right_percent = "|| '%'"; + } + growing_buffer* sql_buf = buffer_init( 32 ); - buffer_fadd( sql_buf, "\"%s\".%s %s %s", class_alias, osrfHashGet(field, "name"), op, val ); + buffer_fadd( sql_buf, "\"%s\".%s %s %s%s", class_alias, osrfHashGet(field, "name"), real_op, val, right_percent ); char* pred = buffer_release( sql_buf ); free( val ); -- 2.43.2