#ifdef PCRUD
static jsonObject* verifyUserPCRUD( osrfMethodContext* );
static int verifyObjectPCRUD( osrfMethodContext*, const jsonObject* );
+static jsonObject* single_hash( const char* key, const char* value );
#endif
static int child_initialized = 0; /* boolean */
}
if (fetch) {
- jsonObject* _tmp_params = jsonParseStringFmt("{\"%s\":\"%s\"}", pkey, pkey_value);
+ jsonObject* _tmp_params = single_hash( pkey, pkey_value );
jsonObject* _list = doFieldmapperSearch(
ctx, class, _tmp_params, NULL, &err );
char* foreign_pkey = osrfHashGet(fcontext, "field");
char* foreign_pkey_value = oilsFMGetString(param, osrfHashGet(fcontext, "fkey"));
- jsonObject* _tmp_params = jsonParseStringFmt(
- "{\"%s\":\"%s\"}",
- foreign_pkey,
- foreign_pkey_value
- );
+ jsonObject* _tmp_params = single_hash( foreign_pkey, foreign_pkey_value );
jsonObject* _list = doFieldmapperSearch(
ctx, osrfHashGet( oilsIDL(), class_name ), _tmp_params, NULL, &err );
osrfHash* foreign_link_hash = oilsIDLFindPath( "/%s/links/%s", _fparam->classname, flink );
- foreign_pkey_value = oilsFMGetString(_fparam, flink);
- foreign_pkey = osrfHashGet( foreign_link_hash, "key" );
+ foreign_pkey_value = oilsFMGetString(_fparam, flink);
+ foreign_pkey = osrfHashGet( foreign_link_hash, "key" );
- _tmp_params = jsonParseStringFmt(
- "{\"%s\":\"%s\"}",
- foreign_pkey,
- foreign_pkey_value
- );
+ _tmp_params = single_hash( foreign_pkey, foreign_pkey_value );
_list = doFieldmapperSearch(
ctx,
return OK;
}
+
+/*
+Utility function: create a JSON_HASH with a single key/value pair.
+This function is equivalent to:
+
+ jsonParseStringFmt( "{\"%s\":\"%s\"}", key, value )
+
+...but faster because it doesn't create and parse a JSON string.
+*/
+static jsonObject* single_hash( const char* key, const char* value ) {
+ // Sanity checks
+ if( ! key ) key = "";
+ if( ! value ) value = "";
+
+ jsonObject* hash = jsonNewObjectType( JSON_HASH );
+ jsonObjectSetKey( hash, key, jsonNewObject( value ) );
+ return hash;
+}
#endif
}
} // end while
- jsonIteratorFree(order_itr);
+ jsonIteratorFree(order_itr);
} else if ( snode->type == JSON_ARRAY ) {
// Array is a list of fields from the current class
- jsonIterator* order_itr = jsonNewIterator( snode );
- while ( (onode = jsonIteratorNext( order_itr )) ) {
+ unsigned long order_idx = 0;
+ while(( onode = jsonObjectGetIndex( snode, order_idx++ ) )) {
const char* _f = jsonObjectGetString( onode );
ctx->request,
"Invalid field in ORDER BY clause -- see error log for more details"
);
- jsonIteratorFree( order_itr );
jsonIteratorFree( class_itr );
buffer_free( order_buf );
free(core_class);
ctx->request,
"Virtual field in ORDER BY clause -- see error log for more details"
);
- jsonIteratorFree( order_itr );
jsonIteratorFree( class_itr );
buffer_free( order_buf );
free(core_class);
buffer_fadd( order_buf, "\"%s\".%s", class_itr->key, _f);
} // end while
- // jsonIteratorFree(order_itr);
-
-
+
// IT'S THE OOOOOOOOOOOLD STYLE!
} else {
osrfLogError(OSRF_LOG_MARK,
return NULL;
}
} // end while
+ jsonIteratorFree( class_itr );
} else {
osrfLogError(OSRF_LOG_MARK,
"%s: Malformed ORDER BY clause; expected JSON_HASH or JSON_ARRAY, found %s",
if (defaultselhash) jsonObjectFree(defaultselhash);
return NULL;
}
- // jsonIteratorFree(class_itr);
if( order_buf )
order_by_list = buffer_release( order_buf );