json_query boolean function param support
authorBill Erickson <berick@esilibrary.com>
Tue, 13 Dec 2011 16:03:23 +0000 (11:03 -0500)
committerMike Rylander <mrylander@gmail.com>
Tue, 13 Dec 2011 16:49:58 +0000 (11:49 -0500)
Solves the following problem when passing boolean parameter values to
json_query functions using the 'from' construct.

E.g.  {"from" : ["some_func_name", true]}

oils_sql.c:2568 open-ils.cstore: Error quoting key string [(null)]

Signed-off-by: Bill Erickson <berick@esilibrary.com>
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/src/c-apps/oils_sql.c

index b79c579..e0b545c 100644 (file)
@@ -2560,16 +2560,24 @@ static char* searchValueTransform( const jsonObject* array ) {
                if( func_item->type == JSON_NULL ) {
                        buffer_add( sql_buf, "NULL" );
                } else {
-                       char* val = jsonObjectToSimpleString( func_item );
-                       if( dbi_conn_quote_string( dbhandle, &val )) {
-                               OSRF_BUFFER_ADD( sql_buf, val );
-                               free( val );
+                       if( func_item->type == JSON_BOOL ) {
+                               if( jsonBoolIsTrue(func_item) ) {
+                                       buffer_add( sql_buf, "TRUE" );
+                               } else {
+                                       buffer_add( sql_buf, "FALSE" );
+                               }
                        } else {
-                               osrfLogError( OSRF_LOG_MARK, "%s: Error quoting key string [%s]",
-                                       modulename, val );
-                               buffer_free( sql_buf );
-                               free( val );
-                               return NULL;
+                               char* val = jsonObjectToSimpleString( func_item );
+                               if( dbi_conn_quote_string( dbhandle, &val )) {
+                                       OSRF_BUFFER_ADD( sql_buf, val );
+                                       free( val );
+                               } else {
+                                       osrfLogError( OSRF_LOG_MARK, 
+                                               "%s: Error quoting key string [%s]", modulename, val );
+                                       buffer_free( sql_buf );
+                                       free( val );
+                                       return NULL;
+                               }
                        }
                }
        }