1. In osrfAppChildInit(): reduce the scope of the attr variable. Don't call
authorscottmk <scottmk@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 9 Apr 2009 14:42:24 +0000 (14:42 +0000)
committerscottmk <scottmk@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 9 Apr 2009 14:42:24 +0000 (14:42 +0000)
dbi_result_get_field_attribs() unless you're going to use the result.

2. In dbi_result_get_field_attribs(): Eliminate the round trip from string to
number and back to string; just use the string that's already available.

If the string is in a JSON_NUMBER, it's guaranteed to be numeric.  If the
string is in a JSON_STRING, it might not be numeric, and if it isn't, then
PostgreSQL will choke on it.  The old code would silently convert it to zero,
or possibly to some other unintended value.

git-svn-id: svn://svn.open-ils.org/ILS/trunk@12823 dcc99617-32d9-48b4-a31d-7c20da2025e4

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

index afc4ad4..f1e3057 100644 (file)
@@ -365,7 +365,6 @@ int osrfAppChildInit() {
 
     osrfLogInfo(OSRF_LOG_MARK, "%s successfully connected to the database", MODULENAME);
 
-    int attr;
     unsigned short type;
     int i = 0; 
     char* classname;
@@ -411,21 +410,21 @@ int osrfAppChildInit() {
 
                     /* determine the field type and storage attributes */
                     type = dbi_result_get_field_type(result, columnName);
-                    attr = dbi_result_get_field_attribs(result, columnName);
 
                     switch( type ) {
 
-                        case DBI_TYPE_INTEGER :
+                                               case DBI_TYPE_INTEGER : {
 
-                            if ( !osrfHashGet(_f, "primitive") )
-                                osrfHashSet(_f,"number", "primitive");
-
-                            if( attr & DBI_INTEGER_SIZE8 ) 
-                                osrfHashSet(_f,"INT8", "datatype");
-                            else 
-                                osrfHashSet(_f,"INT", "datatype");
-                            break;
+                                                       if ( !osrfHashGet(_f, "primitive") )
+                                                               osrfHashSet(_f,"number", "primitive");
 
+                                                       int attr = dbi_result_get_field_attribs(result, columnName);
+                                                       if( attr & DBI_INTEGER_SIZE8 ) 
+                                                               osrfHashSet(_f,"INT8", "datatype");
+                                                       else 
+                                                               osrfHashSet(_f,"INT", "datatype");
+                                                       break;
+                                               }
                         case DBI_TYPE_DECIMAL :
                             if ( !osrfHashGet(_f, "primitive") )
                                 osrfHashSet(_f,"number", "primitive");
@@ -1618,17 +1617,23 @@ static char* jsonNumberToDBString ( osrfHash* field, const jsonObject* value ) {
        const char* numtype = get_datatype( field );
 
        if ( !strncmp( numtype, "INT", 3 ) ) {
-               if (value->type == JSON_NUMBER) buffer_fadd( val_buf, "%ld", (long)jsonObjectGetNumber(value) );
+               if (value->type == JSON_NUMBER)
+                       //buffer_fadd( val_buf, "%ld", (long)jsonObjectGetNumber(value) );
+                       buffer_fadd( val_buf, jsonObjectGetString( value ) );
                else {
-                       const char* val_str = jsonObjectGetString( value );
-                       buffer_fadd( val_buf, "%ld", atol(val_str) );
+                       //const char* val_str = jsonObjectGetString( value );
+                       //buffer_fadd( val_buf, "%ld", atol(val_str) );
+                       buffer_fadd( val_buf, jsonObjectGetString( value ) );
                }
 
        } else if ( !strcmp( numtype, "NUMERIC" ) ) {
-               if (value->type == JSON_NUMBER) buffer_fadd( val_buf, "%f",  jsonObjectGetNumber(value) );
+               if (value->type == JSON_NUMBER)
+                       //buffer_fadd( val_buf, "%f",  jsonObjectGetNumber(value) );
+                       buffer_fadd( val_buf, jsonObjectGetString( value ) );
                else {
-                       const char* val_str = jsonObjectGetString( value );
-                       buffer_fadd( val_buf, "%f", atof(val_str) );
+                       //const char* val_str = jsonObjectGetString( value );
+                       //buffer_fadd( val_buf, "%f", atof(val_str) );
+                       buffer_fadd( val_buf, jsonObjectGetString( value ) );
                }
 
        } else {