[open-ils-commits] r16538 - trunk/Open-ILS/src/c-apps (scottmk)
svn at svn.open-ils.org
svn at svn.open-ils.org
Mon May 31 15:45:31 EDT 2010
Author: scottmk
Date: 2010-05-31 15:45:26 -0400 (Mon, 31 May 2010)
New Revision: 16538
Modified:
trunk/Open-ILS/src/c-apps/buildSQL.c
trunk/Open-ILS/src/c-apps/oils_storedq.c
Log:
Add support for BETWEEN conditions.
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-31 03:03:03 UTC (rev 16537)
+++ trunk/Open-ILS/src/c-apps/buildSQL.c 2010-05-31 19:45:26 UTC (rev 16538)
@@ -577,8 +577,31 @@
if( expr->negate )
buffer_add( state->sql, "NOT " );
- sqlAddMsg( state, "BETWEEN expressions not yet supported" );
- state->error = 1;
+ buildExpression( state, expr->left_operand );
+ if( state->error ) {
+ sqlAddMsg( state, "Unable to emit left operand in BETWEEN expression # %d",
+ expr->id );
+ break;
+ }
+
+ buffer_add( state->sql, " BETWEEN " );
+
+ buildExpression( state, expr->subexp_list );
+ if( state->error ) {
+ sqlAddMsg( state, "Unable to emit lower limit in BETWEEN expression # %d",
+ expr->id );
+ break;
+ }
+
+ buffer_add( state->sql, " AND " );
+
+ buildExpression( state, expr->subexp_list->next );
+ if( state->error ) {
+ sqlAddMsg( state, "Unable to emit upper limit in BETWEEN expression # %d",
+ expr->id );
+ break;
+ }
+
break;
case EXP_BIND :
if( !expr->bind ) { // Sanity check
Modified: trunk/Open-ILS/src/c-apps/oils_storedq.c
===================================================================
--- trunk/Open-ILS/src/c-apps/oils_storedq.c 2010-05-31 03:03:03 UTC (rev 16537)
+++ trunk/Open-ILS/src/c-apps/oils_storedq.c 2010-05-31 19:45:26 UTC (rev 16538)
@@ -1195,7 +1195,53 @@
BindVar* bind = NULL;
Expression* subexp_list = NULL;
- if( EXP_BIND == type ) {
+ if( EXP_BETWEEN == type ) {
+ // Get the left operand
+ if( -1 == left_operand_id ) {
+ osrfLogWarning( OSRF_LOG_MARK, sqlAddMsg( state,
+ "No left operand defined for BETWEEN expression # %d", id ));
+ state->error = 1;
+ return NULL;
+ } else {
+ left_operand = getExpression( state, left_operand_id );
+ if( !left_operand ) {
+ osrfLogWarning( OSRF_LOG_MARK, sqlAddMsg( state,
+ "Unable to get left operand in BETWEEN expression # %d", id ));
+ state->error = 1;
+ return NULL;
+ }
+ }
+
+ // Get the end points of the BETWEEN range
+ subexp_list = getExpressionList( state, id );
+ if( state->error ) {
+ osrfLogWarning( OSRF_LOG_MARK, sqlAddMsg( state,
+ "Unable to get subexpressions for BETWEEN expression # %d", id ));
+ expressionFree( left_operand );
+ return NULL;
+ } else if( !subexp_list ) {
+ osrfLogWarning( OSRF_LOG_MARK, sqlAddMsg( state,
+ "BETWEEN range is empty in expression # %d", id ));
+ state->error = 1;
+ expressionFree( left_operand );
+ return NULL;
+ } else if( !subexp_list->next ) {
+ osrfLogWarning( OSRF_LOG_MARK, sqlAddMsg( state,
+ "BETWEEN range has only one end point in expression # %d", id ));
+ state->error = 1;
+ expressionListFree( subexp_list );
+ expressionFree( left_operand );
+ return NULL;
+ } else if( subexp_list->next->next ) {
+ osrfLogWarning( OSRF_LOG_MARK, sqlAddMsg( state,
+ "BETWEEN range has more than two subexpressions in expression # %d", id ));
+ state->error = 1;
+ expressionListFree( subexp_list );
+ expressionFree( left_operand );
+ return NULL;
+ }
+
+ } else if( EXP_BIND == type ) {
if( bind_variable ) {
// To do: Build a BindVar
bind = getBindVar( state, bind_variable );
@@ -1225,6 +1271,22 @@
}
}
+ } else if( EXP_EXIST == type ) {
+ if( -1 == subquery_id ) {
+ osrfLogWarning( OSRF_LOG_MARK, sqlAddMsg( state,
+ "Internal error: No subquery found for EXIST expression # %d", id ));
+ state->error = 1;
+ return NULL;
+ } else {
+ subquery = getStoredQuery( state, subquery_id );
+ if( !subquery ) {
+ osrfLogWarning( OSRF_LOG_MARK, sqlAddMsg( state,
+ "Unable to load subquery for EXIST expression # %d", id ));
+ state->error = 1;
+ return NULL;
+ }
+ }
+
} else if( EXP_FUNCTION == type ) {
if( !function_name ) {
osrfLogWarning( OSRF_LOG_MARK, sqlAddMsg( state,
@@ -1297,21 +1359,6 @@
return NULL;
}
}
- } else if( EXP_EXIST == type ) {
- if( -1 == subquery_id ) {
- osrfLogWarning( OSRF_LOG_MARK, sqlAddMsg( state,
- "Internal error: No subquery found for EXIST expression # %d", id ));
- state->error = 1;
- return NULL;
- } else {
- subquery = getStoredQuery( state, subquery_id );
- if( !subquery ) {
- osrfLogWarning( OSRF_LOG_MARK, sqlAddMsg( state,
- "Unable to load subquery for EXIST expression # %d", id ));
- state->error = 1;
- return NULL;
- }
- }
} else if( EXP_NUMBER == type ) {
if( !literal ) {
More information about the open-ils-commits
mailing list