From: miker Date: Thu, 21 Sep 2006 17:01:35 +0000 (+0000) Subject: handle embeded FM objects during insert/update X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=5f758e68f54a55b5dec4a59857a8ec90e4f69a13;p=Evergreen.git handle embeded FM objects during insert/update git-svn-id: svn://svn.open-ils.org/ILS/trunk@6180 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/src/c-apps/oils_cstore.c b/Open-ILS/src/c-apps/oils_cstore.c index 71471573a3..3773cc2239 100644 --- a/Open-ILS/src/c-apps/oils_cstore.c +++ b/Open-ILS/src/c-apps/oils_cstore.c @@ -693,8 +693,29 @@ jsonObject* doCreate(osrfMethodContext* ctx, int* err ) { if(!( strcmp( osrfHashGet(osrfHashGet(fields,field_name), "virtual"), "true" ) )) continue; - int pos = atoi(osrfHashGet(field, "array_position")); - char* value = jsonObjectToSimpleString( jsonObjectGetIndex( target, pos ) ); + jsonObject* field_object = jsonObjectGetIndex( target, atoi(osrfHashGet(field, "array_position")) ); + + char* value; + if (field_object && field_object->classname) { + value = jsonObjectToSimpleString( + jsonObjectGetIndex( + field_object, + atoi( + osrfHashGet( + osrfHashGet( + oilsIDLFindPath("/%s/fields", field_object->classname), + (char*)oilsIDLFindPath("/%s/primarykey", field_object->classname) + ), + "array_position" + ) + ) + ) + ); + + } else { + value = jsonObjectToSimpleString( field_object ); + } + if (first) { first = 0; @@ -705,7 +726,7 @@ jsonObject* doCreate(osrfMethodContext* ctx, int* err ) { buffer_add(col_buf, field_name); - if (!jsonObjectGetIndex(target, pos) || jsonObjectGetIndex(target, pos)->type == JSON_NULL) { + if (!field_object || field_object->type == JSON_NULL) { buffer_add( val_buf, "DEFAULT" ); } else if ( !strcmp(osrfHashGet(field, "primitive"), "number") ) { @@ -1205,7 +1226,9 @@ char* searchPredicate ( osrfHash* field, jsonObject* node ) { char* buildSELECT ( jsonObject* search_hash, jsonObject* order_hash, osrfHash* meta, osrfMethodContext* ctx ) { - osrfHash* links = osrfHashGet(meta, "links"); + // XXX this will be used for joins, I think + //osrfHash* links = osrfHashGet(meta, "links"); + osrfHash* fields = osrfHashGet(meta, "fields"); char* core_class = osrfHashGet(meta, "classname"); @@ -1687,12 +1710,32 @@ jsonObject* doUpdate(osrfMethodContext* ctx, int* err ) { if(!( strcmp( field_name, pkey ) )) continue; if(!( strcmp( osrfHashGet(osrfHashGet(fields,field_name), "virtual"), "true" ) )) continue; - int pos = atoi(osrfHashGet(field, "array_position")); - char* value = jsonObjectToSimpleString( jsonObjectGetIndex( target, pos ) ); + jsonObject* field_object = jsonObjectGetIndex( target, atoi(osrfHashGet(field, "array_position")) ); + + char* value; + if (field_object && field_object->classname) { + value = jsonObjectToSimpleString( + jsonObjectGetIndex( + field_object, + atoi( + osrfHashGet( + osrfHashGet( + oilsIDLFindPath("/%s/fields", field_object->classname), + (char*)oilsIDLFindPath("/%s/primarykey", field_object->classname) + ), + "array_position" + ) + ) + ) + ); + + } else { + value = jsonObjectToSimpleString( field_object ); + } osrfLogDebug( OSRF_LOG_MARK, "Updating %s object with %s = %s", osrfHashGet(meta, "fieldmapper"), field_name, value); - if (!jsonObjectGetIndex(target, pos) || jsonObjectGetIndex(target, pos)->type == JSON_NULL) { + if (!field_object || field_object->type == JSON_NULL) { if ( !(!( strcmp( osrfHashGet(meta, "classname"), "au" ) ) && !( strcmp( field_name, "passwd" ) )) ) { // arg at the special case! if (first) first = 0; else buffer_add(sql, ",");