[open-ils-commits] r12823 - trunk/Open-ILS/src/c-apps (scottmk)

svn at svn.open-ils.org svn at svn.open-ils.org
Thu Apr 9 10:42:26 EDT 2009


Author: scottmk
Date: 2009-04-09 10:42:24 -0400 (Thu, 09 Apr 2009)
New Revision: 12823

Modified:
   trunk/Open-ILS/src/c-apps/oils_cstore.c
Log:
1. In osrfAppChildInit(): reduce the scope of the attr variable.  Don't call
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.


Modified: trunk/Open-ILS/src/c-apps/oils_cstore.c
===================================================================
--- trunk/Open-ILS/src/c-apps/oils_cstore.c	2009-04-08 16:07:41 UTC (rev 12822)
+++ trunk/Open-ILS/src/c-apps/oils_cstore.c	2009-04-09 14:42:24 UTC (rev 12823)
@@ -365,7 +365,6 @@
 
     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 @@
 
                     /* 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 ( !osrfHashGet(_f, "primitive") )
+								osrfHashSet(_f,"number", "primitive");
 
-                            if( attr & DBI_INTEGER_SIZE8 ) 
-                                osrfHashSet(_f,"INT8", "datatype");
-                            else 
-                                osrfHashSet(_f,"INT", "datatype");
-                            break;
-
+							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 @@
 	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 {



More information about the open-ils-commits mailing list