[open-ils-commits] r16451 - trunk/Open-ILS/src/c-apps (scottmk)
svn at svn.open-ils.org
svn at svn.open-ils.org
Wed May 19 10:11:31 EDT 2010
Author: scottmk
Date: 2010-05-19 10:11:29 -0400 (Wed, 19 May 2010)
New Revision: 16451
Modified:
trunk/Open-ILS/src/c-apps/oils_execsql.c
Log:
Make sure that all bind variables have been assigned values
before trying to execute a query.
M Open-ILS/src/c-apps/oils_execsql.c
Modified: trunk/Open-ILS/src/c-apps/oils_execsql.c
===================================================================
--- trunk/Open-ILS/src/c-apps/oils_execsql.c 2010-05-19 12:46:18 UTC (rev 16450)
+++ trunk/Open-ILS/src/c-apps/oils_execsql.c 2010-05-19 14:11:29 UTC (rev 16451)
@@ -14,6 +14,7 @@
static jsonObject* get_row( BuildSQLState* state );
static jsonObject* get_date_column( dbi_result result, int col_idx );
+static int values_missing( BuildSQLState* state );
/**
@brief Execute the current SQL statement and return the first row.
@@ -29,6 +30,14 @@
if( !state )
return NULL;
+ // Make sure all the bind variables have values for them
+ if( !state->values_required && values_missing( state )) {
+ state->error = 1;
+ osrfLogError( OSRF_LOG_MARK, sqlAddMsg( state,
+ "Unable to execute query: values not available for all bind variables\n" ));
+ return NULL;
+ }
+
if( state->result )
dbi_result_free( state->result );
@@ -162,3 +171,28 @@
return jsonNewObject( timestring );
}
+
+/**
+ @brief Determine whether all bind variables have values supplied for them.
+ @param state Pointer to the query-building context.
+ @return The number of bind variables with no available value.
+*/
+static int values_missing( BuildSQLState* state ) {
+ if( !state->bindvar_list || osrfHashGetCount( state->bindvar_list ) == 0 )
+ return 0; // Nothing to count
+
+ int count = 0;
+ osrfHashIterator* iter = osrfNewHashIterator( state->bindvar_list );
+
+ BindVar* bind = NULL;
+ while(( bind = osrfHashIteratorNext( iter ))) {
+ if( !bind->actual_value && !bind->default_value ) {
+ sqlAddMsg( state, "No value for bind value \"%s\", with label \"%s\"",
+ bind->name, bind->label );
+ ++count;
+ }
+ }
+
+ osrfHashIteratorFree( iter );
+ return count;
+}
More information about the open-ils-commits
mailing list