From cbc3c8528ca6a6596dc63103c6d629452fd3794a Mon Sep 17 00:00:00 2001 From: scottmk Date: Fri, 30 Apr 2010 20:39:29 +0000 Subject: [PATCH] Use the oilsConnectDB function to connect to the database, instead of using replicated code. M Open-ILS/src/c-apps/oils_pcrud.c M Open-ILS/src/c-apps/oils_rstore.c M Open-ILS/src/c-apps/oils_cstore.c git-svn-id: svn://svn.open-ils.org/ILS/trunk@16363 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/c-apps/oils_cstore.c | 46 ++------------------------------------- Open-ILS/src/c-apps/oils_pcrud.c | 46 ++------------------------------------- Open-ILS/src/c-apps/oils_rstore.c | 46 ++------------------------------------- 3 files changed, 6 insertions(+), 132 deletions(-) diff --git a/Open-ILS/src/c-apps/oils_cstore.c b/Open-ILS/src/c-apps/oils_cstore.c index 97bd43af8..a22f30657 100644 --- a/Open-ILS/src/c-apps/oils_cstore.c +++ b/Open-ILS/src/c-apps/oils_cstore.c @@ -274,53 +274,11 @@ int osrfAppInitialize() { */ int osrfAppChildInit() { - osrfLogDebug(OSRF_LOG_MARK, "Attempting to initialize libdbi..."); - dbi_initialize(NULL); - osrfLogDebug(OSRF_LOG_MARK, "... libdbi initialized."); - - char* driver = osrf_settings_host_value("/apps/%s/app_settings/driver", modulename ); - char* user = osrf_settings_host_value("/apps/%s/app_settings/database/user", modulename ); - char* host = osrf_settings_host_value("/apps/%s/app_settings/database/host", modulename ); - char* port = osrf_settings_host_value("/apps/%s/app_settings/database/port", modulename ); - char* db = osrf_settings_host_value("/apps/%s/app_settings/database/db", modulename ); - char* pw = osrf_settings_host_value("/apps/%s/app_settings/database/pw", modulename ); - - osrfLogDebug(OSRF_LOG_MARK, "Attempting to load the database driver [%s]...", driver); - writehandle = dbi_conn_new(driver); - - if(!writehandle) { - osrfLogError(OSRF_LOG_MARK, "Error loading database driver [%s]", driver); + writehandle = oilsConnectDB( modulename ); + if( !writehandle ) return -1; - } - osrfLogDebug(OSRF_LOG_MARK, "Database driver [%s] seems OK", driver); - - osrfLogInfo(OSRF_LOG_MARK, "%s connecting to database. host=%s, " - "port=%s, user=%s, db=%s", modulename, host, port, user, db ); - - if(host) dbi_conn_set_option(writehandle, "host", host ); - if(port) dbi_conn_set_option_numeric( writehandle, "port", atoi(port) ); - if(user) dbi_conn_set_option(writehandle, "username", user); - if(pw) dbi_conn_set_option(writehandle, "password", pw ); - if(db) dbi_conn_set_option(writehandle, "dbname", db ); - - free(user); - free(host); - free(port); - free(db); - free(pw); - - const char* err; - if (dbi_conn_connect(writehandle) < 0) { - sleep(1); - if (dbi_conn_connect(writehandle) < 0) { - dbi_conn_error(writehandle, &err); - osrfLogError( OSRF_LOG_MARK, "Error connecting to database: %s", err); - return -1; - } - } oilsSetDBConnection( writehandle ); - osrfLogInfo(OSRF_LOG_MARK, "%s successfully connected to the database", modulename ); // Add datatypes from database to the fields in the IDL if( oilsExtendIDL() ) { diff --git a/Open-ILS/src/c-apps/oils_pcrud.c b/Open-ILS/src/c-apps/oils_pcrud.c index 02653c8c3..8dbd48a49 100644 --- a/Open-ILS/src/c-apps/oils_pcrud.c +++ b/Open-ILS/src/c-apps/oils_pcrud.c @@ -274,53 +274,11 @@ int osrfAppInitialize() { */ int osrfAppChildInit() { - osrfLogDebug(OSRF_LOG_MARK, "Attempting to initialize libdbi..."); - dbi_initialize(NULL); - osrfLogDebug(OSRF_LOG_MARK, "... libdbi initialized."); - - char* driver = osrf_settings_host_value("/apps/%s/app_settings/driver", modulename ); - char* user = osrf_settings_host_value("/apps/%s/app_settings/database/user", modulename ); - char* host = osrf_settings_host_value("/apps/%s/app_settings/database/host", modulename ); - char* port = osrf_settings_host_value("/apps/%s/app_settings/database/port", modulename ); - char* db = osrf_settings_host_value("/apps/%s/app_settings/database/db", modulename ); - char* pw = osrf_settings_host_value("/apps/%s/app_settings/database/pw", modulename ); - - osrfLogDebug(OSRF_LOG_MARK, "Attempting to load the database driver [%s]...", driver); - writehandle = dbi_conn_new(driver); - - if(!writehandle) { - osrfLogError(OSRF_LOG_MARK, "Error loading database driver [%s]", driver); + writehandle = oilsConnectDB( modulename ); + if( !writehandle ) return -1; - } - osrfLogDebug(OSRF_LOG_MARK, "Database driver [%s] seems OK", driver); - - osrfLogInfo(OSRF_LOG_MARK, "%s connecting to database. host=%s, " - "port=%s, user=%s, db=%s", modulename, host, port, user, db ); - - if(host) dbi_conn_set_option(writehandle, "host", host ); - if(port) dbi_conn_set_option_numeric( writehandle, "port", atoi(port) ); - if(user) dbi_conn_set_option(writehandle, "username", user); - if(pw) dbi_conn_set_option(writehandle, "password", pw ); - if(db) dbi_conn_set_option(writehandle, "dbname", db ); - - free(user); - free(host); - free(port); - free(db); - free(pw); - - const char* err; - if (dbi_conn_connect(writehandle) < 0) { - sleep(1); - if (dbi_conn_connect(writehandle) < 0) { - dbi_conn_error(writehandle, &err); - osrfLogError( OSRF_LOG_MARK, "Error connecting to database: %s", err); - return -1; - } - } oilsSetDBConnection( writehandle ); - osrfLogInfo(OSRF_LOG_MARK, "%s successfully connected to the database", modulename ); // Add datatypes from database to the fields in the IDL if( oilsExtendIDL() ) { diff --git a/Open-ILS/src/c-apps/oils_rstore.c b/Open-ILS/src/c-apps/oils_rstore.c index 582e1c7c3..50e98e959 100644 --- a/Open-ILS/src/c-apps/oils_rstore.c +++ b/Open-ILS/src/c-apps/oils_rstore.c @@ -274,53 +274,11 @@ int osrfAppInitialize() { */ int osrfAppChildInit() { - osrfLogDebug(OSRF_LOG_MARK, "Attempting to initialize libdbi..."); - dbi_initialize(NULL); - osrfLogDebug(OSRF_LOG_MARK, "... libdbi initialized."); - - char* driver = osrf_settings_host_value("/apps/%s/app_settings/driver", modulename ); - char* user = osrf_settings_host_value("/apps/%s/app_settings/database/user", modulename ); - char* host = osrf_settings_host_value("/apps/%s/app_settings/database/host", modulename ); - char* port = osrf_settings_host_value("/apps/%s/app_settings/database/port", modulename ); - char* db = osrf_settings_host_value("/apps/%s/app_settings/database/db", modulename ); - char* pw = osrf_settings_host_value("/apps/%s/app_settings/database/pw", modulename ); - - osrfLogDebug(OSRF_LOG_MARK, "Attempting to load the database driver [%s]...", driver); - writehandle = dbi_conn_new(driver); - - if(!writehandle) { - osrfLogError(OSRF_LOG_MARK, "Error loading database driver [%s]", driver); + writehandle = oilsConnectDB( modulename ); + if( !writehandle ) return -1; - } - osrfLogDebug(OSRF_LOG_MARK, "Database driver [%s] seems OK", driver); - - osrfLogInfo(OSRF_LOG_MARK, "%s connecting to database. host=%s, " - "port=%s, user=%s, db=%s", modulename, host, port, user, db ); - - if(host) dbi_conn_set_option(writehandle, "host", host ); - if(port) dbi_conn_set_option_numeric( writehandle, "port", atoi(port) ); - if(user) dbi_conn_set_option(writehandle, "username", user); - if(pw) dbi_conn_set_option(writehandle, "password", pw ); - if(db) dbi_conn_set_option(writehandle, "dbname", db ); - - free(user); - free(host); - free(port); - free(db); - free(pw); - - const char* err; - if (dbi_conn_connect(writehandle) < 0) { - sleep(1); - if (dbi_conn_connect(writehandle) < 0) { - dbi_conn_error(writehandle, &err); - osrfLogError( OSRF_LOG_MARK, "Error connecting to database: %s", err); - return -1; - } - } oilsSetDBConnection( writehandle ); - osrfLogInfo(OSRF_LOG_MARK, "%s successfully connected to the database", modulename ); // Add datatypes from database to the fields in the IDL if( oilsExtendIDL() ) { -- 2.11.0