Support IN lists.
authorscottmk <scottmk@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 28 May 2010 03:35:32 +0000 (03:35 +0000)
committerscottmk <scottmk@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 28 May 2010 03:35:32 +0000 (03:35 +0000)
M    Open-ILS/src/c-apps/oils_storedq.c
M    Open-ILS/src/c-apps/buildSQL.c

git-svn-id: svn://svn.open-ils.org/ILS/trunk@16527 dcc99617-32d9-48b4-a31d-7c20da2025e4

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

index 3fcf85e..af0e27c 100644 (file)
@@ -665,17 +665,24 @@ static void buildExpression( BuildSQLState* state, const Expression* expr ) {
                                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, ')' );
                                        }
                                }
                        }
index 3b01840..7ecd4ff 100644 (file)
@@ -1187,7 +1187,26 @@ static Expression* constructExpression( BuildSQLState* state, dbi_result result
        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 @@ static Expression* constructExpression( BuildSQLState* state, dbi_result result
                }
 
                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 @@ static Expression* constructExpression( BuildSQLState* state, dbi_result result
                                "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 @@ static Expression* constructExpression( BuildSQLState* state, dbi_result result
                        }
                        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