From 5919cd2a81b5166854761e42e5c6465e7c1f54b3 Mon Sep 17 00:00:00 2001 From: miker Date: Mon, 17 Jul 2006 21:49:13 +0000 Subject: [PATCH] fixing short-object bug; rolling back on unexpected session end; git-svn-id: svn://svn.open-ils.org/ILS/trunk@5049 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/c-apps/oils_cstore.c | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/Open-ILS/src/c-apps/oils_cstore.c b/Open-ILS/src/c-apps/oils_cstore.c index dc15b72761..6f1edb0f71 100644 --- a/Open-ILS/src/c-apps/oils_cstore.c +++ b/Open-ILS/src/c-apps/oils_cstore.c @@ -327,8 +327,11 @@ void userDataFree( void* blob ) { } void sessionDataFree( char* key, void* item ) { - if (!(strcmp(key,"xact_id"))) + if (!(strcmp(key,"xact_id"))) { + if (writehandle) + dbi_conn_query(writehandle, "ROLLBACK;"); free(item); + } return; } @@ -635,7 +638,11 @@ jsonObject* doCreate(osrfMethodContext* ctx, int* err ) { return jsonNULL; } - if (!osrfHashGet( (osrfHash*)ctx->session->userData, "xact_id" )) { + osrfLogDebug( OSRF_LOG_MARK, "Object seems to be of the correct type" ); + + if (!ctx->session || !ctx->session->userData || !osrfHashGet( (osrfHash*)ctx->session->userData, "xact_id" )) { + osrfLogError( OSRF_LOG_MARK, "No active transaction -- required for CREATE" ); + osrfAppSessionStatus( ctx->session, OSRF_STATUS_BADREQUEST, @@ -647,6 +654,8 @@ jsonObject* doCreate(osrfMethodContext* ctx, int* err ) { return jsonNULL; } + osrfLogDebug( OSRF_LOG_MARK, "There is a transaction running..." ); + dbhandle = writehandle; osrfHash* fields = osrfHashGet(meta, "fields"); @@ -661,6 +670,7 @@ jsonObject* doCreate(osrfMethodContext* ctx, int* err ) { buffer_add(col_buf,"("); buffer_add(val_buf,"VALUES ("); + int i = 0; int first = 1; char* field_name; @@ -671,9 +681,13 @@ jsonObject* doCreate(osrfMethodContext* ctx, int* err ) { if(!( strcmp( osrfHashGet(osrfHashGet(fields,field_name), "virtual"), "true" ) )) continue; + osrfLogDebug( OSRF_LOG_MARK, "HERE..." ); + int pos = atoi(osrfHashGet(field, "array_position")); char* value = jsonObjectToSimpleString( jsonObjectGetIndex( target, pos ) ); + osrfLogDebug( OSRF_LOG_MARK, "HERE..." ); + if (first) { first = 0; } else { @@ -683,10 +697,16 @@ jsonObject* doCreate(osrfMethodContext* ctx, int* err ) { buffer_add(col_buf, field_name); - if (jsonObjectGetIndex(target, pos)->type == JSON_NULL) { + osrfLogDebug( OSRF_LOG_MARK, "HERE..." ); + + if (!jsonObjectGetIndex(target, pos) || jsonObjectGetIndex(target, pos)->type == JSON_NULL) { + osrfLogDebug( OSRF_LOG_MARK, "HERE..." ); + buffer_add( val_buf, "DEFAULT" ); } else if ( !strcmp(osrfHashGet(field, "primitive"), "number") ) { + osrfLogDebug( OSRF_LOG_MARK, "HERE..." ); + if ( !strcmp(osrfHashGet(field, "datatype"), "INT8") ) { buffer_fadd( val_buf, "%lld", atol(value) ); @@ -697,6 +717,8 @@ jsonObject* doCreate(osrfMethodContext* ctx, int* err ) { buffer_fadd( val_buf, "%f", atof(value) ); } } else { + osrfLogDebug( OSRF_LOG_MARK, "HERE..." ); + if ( dbi_conn_quote_string(writehandle, &value) ) { buffer_fadd( val_buf, "%s", value ); @@ -718,10 +740,13 @@ jsonObject* doCreate(osrfMethodContext* ctx, int* err ) { } } + osrfLogDebug( OSRF_LOG_MARK, "HERE..." ); + free(value); } + buffer_add(col_buf,")"); buffer_add(val_buf,")"); @@ -1585,7 +1610,7 @@ jsonObject* doUpdate(osrfMethodContext* ctx, int* err ) { osrfLogDebug( OSRF_LOG_MARK, "Updating %s object with %s = %s", osrfHashGet(meta, "fieldmapper"), field_name, value); - if (jsonObjectGetIndex(target, pos)->type == JSON_NULL) { + if (!jsonObjectGetIndex(target, pos) || jsonObjectGetIndex(target, pos)->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, ","); -- 2.11.0