[open-ils-commits] r12035 - trunk/Open-ILS/src/c-apps
svn at svn.open-ils.org
svn at svn.open-ils.org
Sun Feb 1 14:03:33 EST 2009
Author: scottmk
Date: 2009-02-01 14:03:30 -0500 (Sun, 01 Feb 2009)
New Revision: 12035
Modified:
trunk/Open-ILS/src/c-apps/oils_cstore.c
Log:
Rearranged a bit for clarity.
1. In doRetrieve: don't declare obj until we're ready to build it.
2. In doFieldmapperSearch(): reversed an "if" test to clarify what's
an early return and what's mainline logic. Also: don't declare or
create res_list until we know we're going to return it.
Modified: trunk/Open-ILS/src/c-apps/oils_cstore.c
===================================================================
--- trunk/Open-ILS/src/c-apps/oils_cstore.c 2009-02-01 10:14:56 UTC (rev 12034)
+++ trunk/Open-ILS/src/c-apps/oils_cstore.c 2009-02-01 19:03:30 UTC (rev 12035)
@@ -1508,8 +1508,6 @@
osrfHash* meta = osrfHashGet( (osrfHash*) ctx->method->userData, "class" );
- jsonObject* obj;
-
char* id = jsonObjectToSimpleString(jsonObjectGetIndex(ctx->params, id_pos));
jsonObject* order_hash = jsonObjectGetIndex(ctx->params, order_pos);
@@ -1541,7 +1539,7 @@
return jsonNULL;
}
- obj = jsonObjectClone( jsonObjectGetIndex(list, 0) );
+ jsonObject* obj = jsonObjectClone( jsonObjectGetIndex(list, 0) );
jsonObjectFree( list );
jsonObjectFree( fake_params );
@@ -3173,38 +3171,11 @@
}
osrfLogDebug(OSRF_LOG_MARK, "%s SQL = %s", MODULENAME, sql);
- dbi_result result = dbi_conn_query(dbhandle, sql);
- jsonObject* res_list = jsonNewObjectType(JSON_ARRAY);
- if(result) {
- osrfLogDebug(OSRF_LOG_MARK, "Query returned with no errors");
- osrfHash* dedup = osrfNewHash();
-
- if (dbi_result_first_row(result)) {
- /* JSONify the result */
- osrfLogDebug(OSRF_LOG_MARK, "Query returned at least one row");
- do {
- obj = oilsMakeFieldmapperFromResult( result, meta );
- char* pkey_val = oilsFMGetString( obj, pkey );
- if ( osrfHashGet( dedup, pkey_val ) ) {
- jsonObjectFree(obj);
- free(pkey_val);
- } else {
- osrfHashSet( dedup, pkey_val, pkey_val );
- jsonObjectPush(res_list, obj);
- }
- } while (dbi_result_next_row(result));
- } else {
- osrfLogDebug(OSRF_LOG_MARK, "%s returned no results for query %s", MODULENAME, sql);
- }
-
- osrfHashFree(dedup);
-
- /* clean up the query */
- dbi_result_free(result);
-
- } else {
- osrfLogError(OSRF_LOG_MARK, "%s: Error retrieving %s with query [%s]", MODULENAME, osrfHashGet(meta, "fieldmapper"), sql);
+ dbi_result result = dbi_conn_query(dbhandle, sql);
+ if( NULL == result ) {
+ osrfLogError(OSRF_LOG_MARK, "%s: Error retrieving %s with query [%s]",
+ MODULENAME, osrfHashGet(meta, "fieldmapper"), sql);
osrfAppSessionStatus(
ctx->session,
OSRF_STATUS_INTERNALSERVERERROR,
@@ -3214,11 +3185,37 @@
);
*err = -1;
free(sql);
- jsonObjectFree(res_list);
return jsonNULL;
+ } else {
+ osrfLogDebug(OSRF_LOG_MARK, "Query returned with no errors");
}
+ jsonObject* res_list = jsonNewObjectType(JSON_ARRAY);
+ osrfHash* dedup = osrfNewHash();
+
+ if (dbi_result_first_row(result)) {
+ /* JSONify the result */
+ osrfLogDebug(OSRF_LOG_MARK, "Query returned at least one row");
+ do {
+ obj = oilsMakeFieldmapperFromResult( result, meta );
+ char* pkey_val = oilsFMGetString( obj, pkey );
+ if ( osrfHashGet( dedup, pkey_val ) ) {
+ jsonObjectFree(obj);
+ free(pkey_val);
+ } else {
+ osrfHashSet( dedup, pkey_val, pkey_val );
+ jsonObjectPush(res_list, obj);
+ }
+ } while (dbi_result_next_row(result));
+ } else {
+ osrfLogDebug(OSRF_LOG_MARK, "%s returned no results for query %s",
+ MODULENAME, sql );
+ }
+
+ osrfHashFree(dedup);
+ /* clean up the query */
+ dbi_result_free(result);
free(sql);
if (res_list->size && order_hash) {
More information about the open-ils-commits
mailing list