From 75d5232bd1378da363a8a148a395b58b0bc901af Mon Sep 17 00:00:00 2001 From: scottmk Date: Thu, 16 Apr 2009 21:48:39 +0000 Subject: [PATCH] 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. git-svn-id: svn://svn.open-ils.org/ILS/trunk@12899 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/c-apps/oils_cstore.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/Open-ILS/src/c-apps/oils_cstore.c b/Open-ILS/src/c-apps/oils_cstore.c index 8a1778e355..b09c83ae39 100644 --- a/Open-ILS/src/c-apps/oils_cstore.c +++ b/Open-ILS/src/c-apps/oils_cstore.c @@ -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, -- 2.11.0