In SELECT(): tweak the logic for handling the "aggregate" tag.
authorscottmk <scottmk@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 3 Mar 2009 16:25:09 +0000 (16:25 +0000)
committerscottmk <scottmk@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 3 Mar 2009 16:25:09 +0000 (16:25 +0000)
Previously we would build a GROUP BY clause if any field
carried the "aggregate" tag, even if the associated value
was always false.  Now we respond to the "aggregate" tag
only if its value is true.

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

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

index d87bcc8..902d53b 100644 (file)
@@ -2628,7 +2628,6 @@ char* SELECT (
 
                // Now build the actual select list
            int sel_pos = 1;
-           //jsonObject* is_agg = jsonObjectFindPath(selhash, "//aggregate");
            first = 1;
            gfirst = 1;
            jsonIterator* selclass_itr = jsonNewIterator( selhash );
@@ -2654,7 +2653,6 @@ char* SELECT (
                                                "Selected class is not defined"
                                        );
                                jsonIteratorFree( selclass_itr );
-                               //jsonObjectFree( is_agg );
                                buffer_free( sql_buf );
                                buffer_free( select_buf );
                                buffer_free( order_buf );
@@ -2720,7 +2718,6 @@ char* SELECT (
                                                "Selected class not in FROM clause in JSON query"
                                        );
                                jsonIteratorFree( selclass_itr );
-                               //jsonObjectFree( is_agg );
                                buffer_free( sql_buf );
                                buffer_free( select_buf );
                                buffer_free( order_buf );
@@ -2773,7 +2770,6 @@ char* SELECT (
                                                        );
                                                jsonIteratorFree( select_itr );
                                                jsonIteratorFree( selclass_itr );
-                                               //jsonObjectFree( is_agg );
                                                buffer_free( sql_buf );
                                                buffer_free( select_buf );
                                                buffer_free( order_buf );
@@ -2801,7 +2797,6 @@ char* SELECT (
                                                        );
                                                jsonIteratorFree( select_itr );
                                                jsonIteratorFree( selclass_itr );
-                                               //jsonObjectFree( is_agg );
                                                buffer_free( sql_buf );
                                                buffer_free( select_buf );
                                                buffer_free( order_buf );
@@ -2856,7 +2851,6 @@ char* SELECT (
                                                        );
                                                jsonIteratorFree( select_itr );
                                                jsonIteratorFree( selclass_itr );
-                                               //jsonObjectFree( is_agg );
                                                buffer_free( sql_buf );
                                                buffer_free( select_buf );
                                                buffer_free( order_buf );
@@ -2884,7 +2878,6 @@ char* SELECT (
                                                        );
                                                jsonIteratorFree( select_itr );
                                                jsonIteratorFree( selclass_itr );
-                                               //jsonObjectFree( is_agg );
                                                buffer_free( sql_buf );
                                                buffer_free( select_buf );
                                                buffer_free( order_buf );
@@ -2919,7 +2912,6 @@ char* SELECT (
                                                                );
                                                        jsonIteratorFree( select_itr );
                                                        jsonIteratorFree( selclass_itr );
-                                                       //jsonObjectFree( is_agg );
                                                        buffer_free( sql_buf );
                                                        buffer_free( select_buf );
                                                        buffer_free( order_buf );
@@ -2971,7 +2963,6 @@ char* SELECT (
                                                );
                                        jsonIteratorFree( select_itr );
                                        jsonIteratorFree( selclass_itr );
-                                       //jsonObjectFree( is_agg );
                                        buffer_free( sql_buf );
                                        buffer_free( select_buf );
                                        buffer_free( order_buf );
@@ -2983,10 +2974,9 @@ char* SELECT (
                                }
 
                                const jsonObject* agg_obj = jsonObjectGetKey( selfield, "aggregate" );
-                               if( agg_obj )
+                               if( obj_is_true( agg_obj ) )
                                        aggregate_found = 1;
-
-                               if( ( ! agg_obj ) || ( ! obj_is_true( agg_obj ) ) ) {
+                               else {
                                        // Append a comma (except for the first one)
                                        // and add the column to a GROUP BY clause
                                        if (gfirst)
@@ -3034,8 +3024,6 @@ char* SELECT (
            } // end while -- iterating across classes
 
         jsonIteratorFree(selclass_itr);
-
-           //if (is_agg) jsonObjectFree(is_agg);
     }