[open-ils-commits] r12156 - trunk/Open-ILS/src/c-apps (miker)
svn at svn.open-ils.org
svn at svn.open-ils.org
Thu Feb 12 01:31:35 EST 2009
Author: miker
Date: 2009-02-12 01:31:32 -0500 (Thu, 12 Feb 2009)
New Revision: 12156
Modified:
trunk/Open-ILS/src/c-apps/oils_cstore.c
Log:
adding IN subquery support
Modified: trunk/Open-ILS/src/c-apps/oils_cstore.c
===================================================================
--- trunk/Open-ILS/src/c-apps/oils_cstore.c 2009-02-11 21:41:26 UTC (rev 12155)
+++ trunk/Open-ILS/src/c-apps/oils_cstore.c 2009-02-12 06:31:32 UTC (rev 12156)
@@ -1629,35 +1629,55 @@
buffer_add(sql_buf, "IN (");
}
- int in_item_index = 0;
- int in_item_first = 1;
- jsonObject* in_item;
- while ( (in_item = jsonObjectGetIndex(node, in_item_index++)) ) {
+ if (node->type == JSON_HASH) {
+ // subquery predicate
+ char* subpred = SELECT(
+ ctx,
+ jsonObjectGetKey( node, "select" ),
+ jsonObjectGetKey( node, "from" ),
+ jsonObjectGetKey( node, "where" ),
+ jsonObjectGetKey( node, "having" ),
+ jsonObjectGetKey( node, "order_by" ),
+ jsonObjectGetKey( node, "limit" ),
+ jsonObjectGetKey( node, "offset" ),
+ SUBSELECT
+ );
- if (in_item_first)
- in_item_first = 0;
- else
- buffer_add(sql_buf, ", ");
+ buffer_add(sql_buf, subpred);
+ free(subpred);
- if ( !strcmp(osrfHashGet(field, "primitive"), "number") ) {
- char* val = jsonNumberToDBString( field, in_item );
- OSRF_BUFFER_ADD( sql_buf, val );
- free(val);
-
- } else {
- char* key_string = jsonObjectToSimpleString(in_item);
- if ( dbi_conn_quote_string(dbhandle, &key_string) ) {
- OSRF_BUFFER_ADD( sql_buf, key_string );
- free(key_string);
- } else {
- osrfLogError(OSRF_LOG_MARK, "%s: Error quoting key string [%s]", MODULENAME, key_string);
- free(key_string);
- buffer_free(sql_buf);
- return NULL;
- }
- }
- }
-
+ } else if (node->type == JSON_ARRAY) {
+ // litteral value list
+ int in_item_index = 0;
+ int in_item_first = 1;
+ jsonObject* in_item;
+ while ( (in_item = jsonObjectGetIndex(node, in_item_index++)) ) {
+
+ if (in_item_first)
+ in_item_first = 0;
+ else
+ buffer_add(sql_buf, ", ");
+
+ if ( !strcmp(osrfHashGet(field, "primitive"), "number") ) {
+ char* val = jsonNumberToDBString( field, in_item );
+ OSRF_BUFFER_ADD( sql_buf, val );
+ free(val);
+
+ } else {
+ char* key_string = jsonObjectToSimpleString(in_item);
+ if ( dbi_conn_quote_string(dbhandle, &key_string) ) {
+ OSRF_BUFFER_ADD( sql_buf, key_string );
+ free(key_string);
+ } else {
+ osrfLogError(OSRF_LOG_MARK, "%s: Error quoting key string [%s]", MODULENAME, key_string);
+ free(key_string);
+ buffer_free(sql_buf);
+ return NULL;
+ }
+ }
+ }
+ }
+
OSRF_BUFFER_ADD_CHAR( sql_buf, ')' );
return buffer_release(sql_buf);
More information about the open-ils-commits
mailing list