Teach cstore et al about predicate-style truth tests in ORDER BY clauses
authorMike Rylander <mrylander@gmail.com>
Wed, 4 Jan 2012 18:32:33 +0000 (13:32 -0500)
committerBill Erickson <berick@esilibrary.com>
Wed, 4 Jan 2012 20:49:53 +0000 (15:49 -0500)
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Signed-off-by: Bill Erickson <berick@esilibrary.com>

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

index e0b545c..99918d5 100644 (file)
@@ -4950,6 +4950,8 @@ static char* buildOrderByFromArray( osrfMethodContext* ctx, const jsonObject* or
                const char* field =
                        jsonObjectGetString( jsonObjectGetKeyConst( order_spec, "field" ));
 
+               jsonObject* compare_to = jsonObjectGetKeyConst( order_spec, "compare" );
+
                if( !field || !class_alias ) {
                        osrfLogError( OSRF_LOG_MARK,
                                "%s: Missing class or field name in field specification of ORDER BY clause",
@@ -5028,6 +5030,24 @@ static char* buildOrderByFromArray( osrfMethodContext* ctx, const jsonObject* or
 
                        OSRF_BUFFER_ADD( order_buf, transform_str );
                        free( transform_str );
+               } else if( compare_to ) {
+                       char* compare_str = searchPredicate( order_class_info, field_def, compare_to, ctx );
+                       if( ! compare_str ) {
+                               if( ctx )
+                                       osrfAppSessionStatus(
+                                               ctx->session,
+                                               OSRF_STATUS_INTERNALSERVERERROR,
+                                               "osrfMethodException",
+                                               ctx->request,
+                                               "Severe query error in ORDER BY clause -- "
+                                               "see error log for more details"
+                                       );
+                               buffer_free( order_buf );
+                               return NULL;
+                       }
+
+                       buffer_fadd( order_buf, "(%s)", compare_str );
+                       free( compare_str );
                }
                else
                        buffer_fadd( order_buf, "\"%s\".%s", class_alias, field );