In oils_cstore.c, tightened validation for partial autojoins, i.e.
authorscottmk <scottmk@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 16 Apr 2009 21:48:39 +0000 (21:48 +0000)
committerscottmk <scottmk@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 16 Apr 2009 21:48:39 +0000 (21:48 +0000)
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.

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

Open-ILS/src/c-apps/oils_cstore.c

index 8a1778e..b09c83a 100644 (file)
@@ -2213,7 +2213,17 @@ static char* searchJOIN ( const jsonObject* join_hash, osrfHash* leftmeta ) {
                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 @@ static char* searchJOIN ( const jsonObject* join_hash, osrfHash* leftmeta ) {
                        }
 
                } 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,