[open-ils-commits] r12268 - trunk/Open-ILS/src/c-apps (scottmk)
svn at svn.open-ils.org
svn at svn.open-ils.org
Sun Feb 22 19:14:06 EST 2009
Author: scottmk
Date: 2009-02-22 19:14:05 -0500 (Sun, 22 Feb 2009)
New Revision: 12268
Modified:
trunk/Open-ILS/src/c-apps/oils_cstore.c
Log:
In the FROM clause: detect and report invalid classes up front,
instead of building a query that is bound to fail.
Modified: trunk/Open-ILS/src/c-apps/oils_cstore.c
===================================================================
--- trunk/Open-ILS/src/c-apps/oils_cstore.c 2009-02-22 21:26:05 UTC (rev 12267)
+++ trunk/Open-ILS/src/c-apps/oils_cstore.c 2009-02-23 00:14:05 UTC (rev 12268)
@@ -275,20 +275,30 @@
static char* getSourceDefinition( osrfHash* class ) {
- char* tabledef = osrfHashGet(class, "tablename");
+ char* tabledef = osrfHashGet(class, "tablename");
- if (!tabledef) {
- growing_buffer* tablebuf = buffer_init(128);
- tabledef = osrfHashGet(class, "source_definition");
- if( !tabledef )
- tabledef = "(null)";
- buffer_fadd( tablebuf, "(%s)", tabledef );
- tabledef = buffer_release(tablebuf);
- } else {
- tabledef = strdup(tabledef);
- }
+ if (tabledef) {
+ tabledef = strdup(tabledef);
+ } else {
+ tabledef = osrfHashGet(class, "source_definition");
+ if( tabledef ) {
+ growing_buffer* tablebuf = buffer_init(128);
+ buffer_fadd( tablebuf, "(%s)", tabledef );
+ tabledef = buffer_release(tablebuf);
+ } else {
+ const char* classname = osrfHashGet( class, "classname" );
+ if( !classname )
+ classname = "???";
+ osrfLogError(
+ OSRF_LOG_MARK,
+ "%s ERROR No tablename or source_definition for class \"%s\"",
+ MODULENAME,
+ classname
+ );
+ }
+ }
- return tabledef;
+ return tabledef;
}
/**
@@ -364,6 +374,8 @@
}
char* tabledef = getSourceDefinition(class);
+ if( !tabledef )
+ tabledef = strdup( "(null)" );
growing_buffer* sql_buf = buffer_init(32);
buffer_fadd( sql_buf, "SELECT * FROM %s AS x WHERE 1=0;", tabledef );
@@ -2139,6 +2151,8 @@
leftclass,
class
);
+ free( fkey );
+ free( field );
buffer_free(join_buf);
if(freeable_hash)
jsonObjectFree(freeable_hash);
@@ -2165,6 +2179,16 @@
free(type);
char* table = getSourceDefinition(idlClass);
+ if( !table ) {
+ free( field );
+ free( fkey );
+ jsonIteratorFree( search_itr );
+ buffer_free( join_buf );
+ if( freeable_hash )
+ jsonObjectFree( freeable_hash );
+ return NULL;
+ }
+
buffer_fadd(join_buf, " %s AS \"%s\" ON ( \"%s\".%s = \"%s\".%s",
table, class, class, field, leftclass, fkey);
free(table);
@@ -2321,6 +2345,8 @@
if (!field) {
char* table = getSourceDefinition(meta);
+ if( !table )
+ table = strdup( "(?)" );
osrfLogError(
OSRF_LOG_MARK,
"%s: Attempt to reference non-existent column %s on %s (%s)",
@@ -2667,7 +2693,26 @@
char* table = NULL;
if (from_function) table = searchValueTransform(join_hash);
else table = getSourceDefinition(core_meta);
-
+
+ if( !table ) {
+ if (ctx)
+ osrfAppSessionStatus(
+ ctx->session,
+ OSRF_STATUS_INTERNALSERVERERROR,
+ "osrfMethodException",
+ ctx->request,
+ "Unable to identify table for core class"
+ );
+ free( col_list );
+ buffer_free( sql_buf );
+ buffer_free( order_buf );
+ buffer_free( group_buf );
+ buffer_free( having_buf );
+ if( defaultselhash ) jsonObjectFree( defaultselhash );
+ free( core_class );
+ return NULL;
+ }
+
// Put it all together
buffer_fadd(sql_buf, "SELECT %s FROM %s AS \"%s\" ", col_list, table, core_class );
free(col_list);
@@ -2677,8 +2722,26 @@
// Now, walk the join tree and add that clause
if ( join_hash ) {
char* join_clause = searchJOIN( join_hash, core_meta );
- buffer_add(sql_buf, join_clause);
- free(join_clause);
+ if( join_clause ) {
+ buffer_add(sql_buf, join_clause);
+ free(join_clause);
+ } else {
+ if (ctx)
+ osrfAppSessionStatus(
+ ctx->session,
+ OSRF_STATUS_INTERNALSERVERERROR,
+ "osrfMethodException",
+ ctx->request,
+ "Unable to construct JOIN clause(s)"
+ );
+ buffer_free( sql_buf );
+ buffer_free( order_buf );
+ buffer_free( group_buf );
+ buffer_free( having_buf );
+ if( defaultselhash ) jsonObjectFree( defaultselhash );
+ free( core_class );
+ return NULL;
+ }
}
// Build a WHERE clause, if there is one
@@ -3011,6 +3074,8 @@
char* col_list = buffer_release(select_buf);
char* table = getSourceDefinition(meta);
+ if( !table )
+ table = strdup( "(null)" );
buffer_fadd(sql_buf, "SELECT %s FROM %s AS \"%s\"", col_list, table, core_class );
free(col_list);
More information about the open-ils-commits
mailing list