Enhance error handling in SELECT(). In two cases,
authorscottmk <scottmk@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 25 Feb 2009 13:36:27 +0000 (13:36 +0000)
committerscottmk <scottmk@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 25 Feb 2009 13:36:27 +0000 (13:36 +0000)
issue a helpful message before bailing out:

1. When the FROM clause is missing or empty

2. When the FROM clause is a JSON_HASH with more
than one entry

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

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

index 2a6824b..e6bf082 100644 (file)
@@ -2423,8 +2423,22 @@ char* SELECT (
        osrfHash* core_meta = NULL;
 
        // punt if there's no core class
-       if (!join_hash || ( join_hash->type == JSON_HASH && !join_hash->size ))
+       if (!join_hash || ( join_hash->type == JSON_HASH && !join_hash->size )) {
+               osrfLogError(
+                       OSRF_LOG_MARK,
+                       "%s: FROM clause is missing or empty",
+                       MODULENAME
+               );
+               if( ctx )
+                       osrfAppSessionStatus(
+                               ctx->session,
+                               OSRF_STATUS_INTERNALSERVERERROR,
+                               "osrfMethodException",
+                               ctx->request,
+                               "FROM clause is missing or empty in JSON query"
+                       );
                return NULL;
+       }
 
        // get the core class -- the only key of the top level FROM clause, or a string
        if (join_hash->type == JSON_HASH) {
@@ -2438,11 +2452,25 @@ char* SELECT (
 
                jsonIteratorFree( tmp_itr );
                snode = NULL;
-               
+
                // There shouldn't be more than one entry in join_hash
-               if( extra )
+               if( extra ) {
+                       osrfLogError(
+                               OSRF_LOG_MARK,
+                               "%s: Malformed FROM clause: extra entry in JSON_HASH",
+                               MODULENAME
+                       );
+                       if( ctx )
+                               osrfAppSessionStatus(
+                                       ctx->session,
+                                       OSRF_STATUS_INTERNALSERVERERROR,
+                                       "osrfMethodException",
+                                       ctx->request,
+                                       "Malformed FROM clause in JSON query"
+                               );
+                       free( core_class );
                        return NULL;    // Malformed join_hash; extra entry
-
+               }
        } else if (join_hash->type == JSON_ARRAY) {
                from_function = 1;
                core_class = jsonObjectToSimpleString( jsonObjectGetIndex(join_hash, 0) );