fixing short-object bug; rolling back on unexpected session end;
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 17 Jul 2006 21:49:13 +0000 (21:49 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 17 Jul 2006 21:49:13 +0000 (21:49 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@5049 dcc99617-32d9-48b4-a31d-7c20da2025e4

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

index dc15b72..6f1edb0 100644 (file)
@@ -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, ",");