[open-ils-commits] r16527 - trunk/Open-ILS/src/c-apps (scottmk)

svn at svn.open-ils.org svn at svn.open-ils.org
Thu May 27 23:35:35 EDT 2010


Author: scottmk
Date: 2010-05-27 23:35:32 -0400 (Thu, 27 May 2010)
New Revision: 16527

Modified:
   trunk/Open-ILS/src/c-apps/buildSQL.c
   trunk/Open-ILS/src/c-apps/oils_storedq.c
Log:
Support IN lists.

M    Open-ILS/src/c-apps/oils_storedq.c
M    Open-ILS/src/c-apps/buildSQL.c


Modified: trunk/Open-ILS/src/c-apps/buildSQL.c
===================================================================
--- trunk/Open-ILS/src/c-apps/buildSQL.c	2010-05-28 01:46:29 UTC (rev 16526)
+++ trunk/Open-ILS/src/c-apps/buildSQL.c	2010-05-28 03:35:32 UTC (rev 16527)
@@ -665,17 +665,24 @@
 				if( !state->error ) {
 					if( expr->negate )
 						buffer_add( state->sql, "NOT " );
+					buffer_add( state->sql, " IN (" );
 
 					if( expr->subquery ) {
-						buffer_add( state->sql, " IN (" );
 						incr_indent( state );
 						build_Query( state, expr->subquery );
-						decr_indent( state );
-						add_newline( state );
-						buffer_add_char( state->sql, ')' );
+						if( state->error )
+							sqlAddMsg( state, "Unable to build subquery for IN condition" );
+						else {
+							decr_indent( state );
+							add_newline( state );
+							buffer_add_char( state->sql, ')' );
+						}
 					} else {
-						sqlAddMsg( state, "IN lists not yet supported" );
-						state->error = 1;
+						buildSeries( state, expr->subexp_list, expr->op );
+						if( state->error )
+							sqlAddMsg( state, "Unable to build IN list" );
+						else
+							buffer_add_char( state->sql, ')' );
 					}
 				}
 			}

Modified: trunk/Open-ILS/src/c-apps/oils_storedq.c
===================================================================
--- trunk/Open-ILS/src/c-apps/oils_storedq.c	2010-05-28 01:46:29 UTC (rev 16526)
+++ trunk/Open-ILS/src/c-apps/oils_storedq.c	2010-05-28 03:35:32 UTC (rev 16527)
@@ -1187,7 +1187,26 @@
 	BindVar* bind = NULL;
 	Expression* subexp_list = NULL;
 
-	if( EXP_OPERATOR == type ) {
+	if( EXP_BIND == type ) {
+		if( bind_variable ) {
+			// To do: Build a BindVar
+			bind = getBindVar( state, bind_variable );
+			if( ! bind ) {
+				osrfLogWarning( OSRF_LOG_MARK, sqlAddMsg( state,
+								"Unable to load bind variable \"%s\" for expression # %d",
+		bind_variable, id ));
+				state->error = 1;
+				return NULL;
+			}
+			PRINT( "\tBind variable is \"%s\"\n", bind_variable );
+		} else {
+			osrfLogWarning( OSRF_LOG_MARK, sqlAddMsg( state,
+							"No variable specified for bind variable expression # %d",
+	   bind_variable, id ));
+			state->error = 1;
+			return NULL;
+		}
+	} else if( EXP_OPERATOR == type ) {
 		// Load left and/or right operands
 		if( -1 == left_operand_id && -1 == right_operand_id ) {
 			osrfLogWarning( OSRF_LOG_MARK, sqlAddMsg( state,
@@ -1233,12 +1252,20 @@
 		}
 
 		if( -1 == subquery_id ) {
-			// To do: load IN list of subexpressions
-			osrfLogWarning( OSRF_LOG_MARK, sqlAddMsg( state,
-				"IN lists not yet supported for expression # %d", id ));
-			state->error = 1;
-			return NULL;
+			// Load an IN list of subexpressions
+			subexp_list = getExpressionList( state, id );
+			if( state->error ) {
+				osrfLogWarning( OSRF_LOG_MARK, sqlAddMsg( state,
+					"Unable to get subexpressions for IN list" ));
+				return NULL;
+			} else if( !subexp_list ) {
+				osrfLogWarning( OSRF_LOG_MARK, sqlAddMsg( state,
+					"IN list is empty in expression # %d", id ));
+				state->error = 1;
+				return NULL;
+			}
 		} else {
+			// Load a subquery
 			subquery = getStoredQuery( state, subquery_id );
 			if( !subquery ) {
 				osrfLogWarning( OSRF_LOG_MARK, sqlAddMsg( state,
@@ -1286,7 +1313,13 @@
 				"Unable to get subexpressions for expression series using operator \"%s\"",
 					operator ? operator : "," ));
 			return NULL;
+		} else if( !subexp_list ) {
+			osrfLogWarning( OSRF_LOG_MARK, sqlAddMsg( state,
+				"Series expression is empty in expression # %d", id ));
+			state->error = 1;
+			return NULL;
 		}
+
 	} else if( EXP_SUBQUERY == type ) {
 		if( -1 == subquery_id ) {
 			osrfLogWarning( OSRF_LOG_MARK, sqlAddMsg( state,
@@ -1310,25 +1343,6 @@
 			}
 			PRINT( "\tExpression is subquery %d\n", subquery_id );
 		}
-	} else if( EXP_BIND == type ) {
-		if( bind_variable ) {
-			// To do: Build a BindVar
-			bind = getBindVar( state, bind_variable );
-			if( ! bind ) {
-				osrfLogWarning( OSRF_LOG_MARK, sqlAddMsg( state,
-					"Unable to load bind variable \"%s\" for expression # %d",
-					bind_variable, id ));
-				state->error = 1;
-				return NULL;
-			}
-			PRINT( "\tBind variable is \"%s\"\n", bind_variable );
-		} else {
-			osrfLogWarning( OSRF_LOG_MARK, sqlAddMsg( state,
-				"No variable specified for bind variable expression # %d",
-			bind_variable, id ));
-			state->error = 1;
-			return NULL;
-		}
 	}
 
 	// Allocate an Expression: from the free list if possible, from the heap if necessary



More information about the open-ils-commits mailing list