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

svn at svn.open-ils.org svn at svn.open-ils.org
Thu Apr 16 17:48:44 EDT 2009


Author: scottmk
Date: 2009-04-16 17:48:39 -0400 (Thu, 16 Apr 2009)
New Revision: 12899

Modified:
   trunk/Open-ILS/src/c-apps/oils_cstore.c
Log:
In oils_cstore.c, tightened validation for partial autojoins, i.e.
when the query specifies only one of the join columns.

When looking up the other join column in the IDL, make sure that the
link used points to the right table.  Also make sure that the reltype
for the link is not "has_many", because that would imply that the
link is virtual, and the designated column doesn't exist in the
database.


Modified: trunk/Open-ILS/src/c-apps/oils_cstore.c
===================================================================
--- trunk/Open-ILS/src/c-apps/oils_cstore.c	2009-04-16 21:33:50 UTC (rev 12898)
+++ trunk/Open-ILS/src/c-apps/oils_cstore.c	2009-04-16 21:48:39 UTC (rev 12899)
@@ -2213,7 +2213,17 @@
 		const char* field = jsonObjectGetString( jsonObjectGetKeyConst( snode, "field" ) );
 
 		if (field && !fkey) {
-			fkey = (const char*)oilsIDLFindPath("/%s/links/%s/key", class, field);
+			// Look up the corresponding join column in the IDL.
+			// The link must be defined in the child table,
+			// and point to the right parent table.
+			osrfHash* idl_link = (osrfHash*) oilsIDLFindPath( "/%s/links/%s", class, field );
+			const char* reltype = NULL;
+			const char* other_class = NULL;
+			reltype = osrfHashGet( idl_link, "reltype" );
+			if( reltype && strcmp( reltype, "has_many" ) )
+				other_class = osrfHashGet( idl_link, "class" );
+			if( other_class && !strcmp( other_class, leftclass ) )
+				fkey = osrfHashGet( idl_link, "key" );
 			if (!fkey) {
 				osrfLogError(
 					OSRF_LOG_MARK,
@@ -2231,7 +2241,17 @@
 			}
 
 		} else if (!field && fkey) {
-			field = (const char*)oilsIDLFindPath("/%s/links/%s/key", leftclass, fkey );
+			// Look up the corresponding join column in the IDL.
+			// The link must be defined in the child table,
+			// and point to the right parent table.
+			osrfHash* idl_link = (osrfHash*) oilsIDLFindPath( "/%s/links/%s", leftclass, fkey );
+			const char* reltype = NULL;
+			const char* other_class = NULL;
+			reltype = osrfHashGet( idl_link, "reltype" );
+			if( reltype && strcmp( reltype, "has_many" ) )
+				other_class = osrfHashGet( idl_link, "class" );
+			if( other_class && !strcmp( other_class, class ) )
+				field = osrfHashGet( idl_link, "key" );
 			if (!field) {
 				osrfLogError(
 					OSRF_LOG_MARK,



More information about the open-ils-commits mailing list