[open-ils-commits] r12313 - trunk/Open-ILS/src/c-apps (scottmk)
svn at svn.open-ils.org
svn at svn.open-ils.org
Fri Feb 27 11:29:45 EST 2009
Author: scottmk
Date: 2009-02-27 11:29:43 -0500 (Fri, 27 Feb 2009)
New Revision: 12313
Modified:
trunk/Open-ILS/src/c-apps/oils_cstore.c
trunk/Open-ILS/src/c-apps/test_json_query.c
Log:
Added some kludgy code to load a database driver, and connect
to it, before testing a JSON query. We don't connect to the
database itself, but we need to connect to the driver or else
dbi_conn_quote_string() won't work.
Modified: trunk/Open-ILS/src/c-apps/oils_cstore.c
===================================================================
--- trunk/Open-ILS/src/c-apps/oils_cstore.c 2009-02-27 02:37:34 UTC (rev 12312)
+++ trunk/Open-ILS/src/c-apps/oils_cstore.c 2009-02-27 16:29:43 UTC (rev 12313)
@@ -467,6 +467,15 @@
return 0;
}
+/*
+ This function is a sleazy hack intended *only* for testing and
+ debugging. Any real server process should initialize the
+ database connection by calling osrfAppChildInit().
+*/
+void set_cstore_dbi_conn( dbi_conn conn ) {
+ dbhandle = writehandle = conn;
+}
+
void userDataFree( void* blob ) {
osrfHashFree( (osrfHash*)blob );
return;
@@ -1793,7 +1802,7 @@
OSRF_BUFFER_ADD_CHAR( sql_buf, ',' );
OSRF_BUFFER_ADD( sql_buf, val );
} else {
- osrfLogError(OSRF_LOG_MARK, "%s: Error quoting key string [%s]", MODULENAME, val);
+ osrfLogError(OSRF_LOG_MARK, "%s: Error quoting key string [%s]", MODULENAME, val);
free(transform_subcolumn);
free(field_transform);
free(val);
Modified: trunk/Open-ILS/src/c-apps/test_json_query.c
===================================================================
--- trunk/Open-ILS/src/c-apps/test_json_query.c 2009-02-27 02:37:34 UTC (rev 12312)
+++ trunk/Open-ILS/src/c-apps/test_json_query.c 2009-02-27 16:29:43 UTC (rev 12313)
@@ -45,11 +45,13 @@
#include <opensrf/osrf_application.h>
#include <opensrf/osrf_app_session.h>
#include <openils/oils_idl.h>
+#include <dbi/dbi.h>
#define DISABLE_I18N 2
#define SELECT_DISTINCT 1
-// Prototype for SELECT(), which is not in any header
+// Prototypes for two functions in oils_cstore.c, which
+// are not defined in any header
char* SELECT (
/* method context */ osrfMethodContext* ctx,
@@ -62,6 +64,7 @@
/* OFFSET */ jsonObject* offset,
/* flags */ int flags
);
+void set_cstore_dbi_conn( dbi_conn conn );
static int obj_is_true( const jsonObject* obj );
static int test_json_query( const char* json_query );
@@ -149,9 +152,33 @@
osrfLogSetLevel( OSRF_LOG_WARNING ); // Suppress informational messages
(void) oilsIDLInit( idl_file_name ); // Load IDL into memory
+ // Load a database driver, connect to it, and install the connection in
+ // the cstore module. We don't actually connect to a database, but we
+ // need the driver to process quoted strings correctly.
+ if( dbi_initialize( NULL ) < 0 ) {
+ printf( "Unable to load database driver\n" );
+ return EXIT_FAILURE;
+ };
+
+ dbi_conn conn = dbi_conn_new( "pgsql" ); // change string if ever necessary
+ if( !conn ) {
+ printf( "Unable to establish dbi connection\n" );
+ dbi_shutdown();
+ return EXIT_FAILURE;
+ }
+
+ set_cstore_dbi_conn( conn );
+
+ // The foregoing is an inelegant kludge. The true, proper, and uniquely
+ // correct thing to do is to load the system settings and then call
+ // osrfAppInitialize() and osrfAppChildInit(). Maybe we'll actually
+ // do that some day, but this will do for now.
+
// Translate the JSON into SQL
int rc = test_json_query( json_query );
+ dbi_conn_close( conn );
+ dbi_shutdown();
if( loaded_json )
free( loaded_json );
More information about the open-ils-commits
mailing list