From: scottmk Date: Fri, 27 Feb 2009 16:29:43 +0000 (+0000) Subject: Added some kludgy code to load a database driver, and connect X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=970a33fa9ad1860d96ee450cdb8ee111e434525a;p=evergreen%2Ftadl.git 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. git-svn-id: svn://svn.open-ils.org/ILS/trunk@12313 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/src/c-apps/oils_cstore.c b/Open-ILS/src/c-apps/oils_cstore.c index fe6ef7c470..66b6118c56 100644 --- a/Open-ILS/src/c-apps/oils_cstore.c +++ b/Open-ILS/src/c-apps/oils_cstore.c @@ -467,6 +467,15 @@ int osrfAppChildInit() { 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 @@ static char* searchFieldTransform (const char* class, osrfHash* field, const jso 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); diff --git a/Open-ILS/src/c-apps/test_json_query.c b/Open-ILS/src/c-apps/test_json_query.c index dc37e4c5dd..c0e73dc538 100644 --- a/Open-ILS/src/c-apps/test_json_query.c +++ b/Open-ILS/src/c-apps/test_json_query.c @@ -45,11 +45,13 @@ Scott McKellar #include #include #include +#include #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 @@ char* SELECT ( /* 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 @@ int main( int argc, char* argv[] ) { 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 );