--- parser3/src/main/pa_sql_driver_manager.C 2003/01/31 12:10:47 1.69.2.8 +++ parser3/src/main/pa_sql_driver_manager.C 2003/03/13 12:34:21 1.69.2.17 @@ -1,11 +1,11 @@ /** @file Parser: sql driver manager implementation. - Copyright (c) 2001, 2003 ArtLebedev Group (http://www.artlebedev.com) + Copyright (c) 2001-2003 ArtLebedev Group (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char* IDENT_SQL_DRIVER_MANAGER_C="$Date: 2003/01/31 12:10:47 $"; +static const char* IDENT_SQL_DRIVER_MANAGER_C="$Date: 2003/03/13 12:34:21 $"; #include "pa_sql_driver_manager.h" #include "ltdl.h" @@ -13,7 +13,6 @@ static const char* IDENT_SQL_DRIVER_MANA #include "pa_sql_connection.h" #include "pa_exception.h" #include "pa_common.h" -#include "pa_value_includes.h" #include "pa_vhash.h" #include "pa_vtable.h" @@ -56,13 +55,16 @@ static void expire_connections( // SQL_Driver_manager SQL_Driver_manager::SQL_Driver_manager(): - prev_expiration_pass_time(0) { + prev_expiration_pass_time(0), is_dlinited(false) { cache_managers.put(StringPtr(new String("sql")), this); } SQL_Driver_manager::~SQL_Driver_manager() { connection_cache.for_each(expire_connections, time(0)+(time_t)1/*=in future=expire all*/); + + if(is_dlinited) + lt_dlexit(); } /// @param aurl protocol://[driver-dependent] @@ -85,6 +87,7 @@ SQL_ConnectionPtr SQL_Driver_manager::ge } } + CharPtr request_url_cstr_ptr; char *request_url_cstr; if(connection) request_url_cstr=0; // calm, compiler @@ -97,7 +100,7 @@ SQL_ConnectionPtr SQL_Driver_manager::ge // make global_url C-string on driver_cache_pool pool StringPtr global_url(new String(arequest_url->cstr(driver_cache_pool))); - request_url_cstr=arequest_url->cstr(); + request_url_cstr=request_url_cstr_ptr=arequest_url->cstr(); char *request_protocol_cstr=lsplit(&request_url_cstr, ':'); // skip "//" after ':' while(*request_url_cstr=='/') @@ -124,12 +127,16 @@ SQL_ConnectionPtr SQL_Driver_manager::ge "undefined protocol '%s'", request_protocol_cstr); - if(lt_dlinit()) - throw Exception(0, - library, - "prepare to dynamic loading failed, %s", lt_dlerror()); + if(!is_dlinited) { + if(lt_dlinit()) + throw Exception(0, + library, + "prepare to dynamic loading failed, %s", lt_dlerror()); + + is_dlinited=true; + } - const char *filename=library->cstr(String::UL_FILE_SPEC); + CharPtr filename=library->cstr(String::UL_FILE_SPEC); lt_dlhandle handle=lt_dlopen(filename); if (!handle) throw Exception(0, @@ -157,13 +164,13 @@ SQL_ConnectionPtr SQL_Driver_manager::ge // initialise by connecting to sql client dynamic link library CharPtr dlopen_file_spec_cstr= dlopen_file_spec && dlopen_file_spec->size()? - dlopen_file_spec->cstr(String::UL_AS_IS):CharPtrZero; - if(const char *error=driver->initialize( + dlopen_file_spec->cstr(String::UL_AS_IS):CharPtr(0); + if(const char* error=driver->initialize( dlopen_file_spec_cstr)) throw Exception(0, library, "driver failed to initialize client library '%s', %s", - dlopen_file_spec_cstr?dlopen_file_spec_cstr:"unspecifed", + dlopen_file_spec_cstr?dlopen_file_spec_cstr.get():"unspecifed", error); // cache it @@ -207,6 +214,7 @@ void SQL_Driver_manager::put_driver_to_c } // connection cache +/// @todo get rid of memory spending Stack [zeros deep inside got accumulated] SQL_ConnectionPtr SQL_Driver_manager::get_connection_from_cache( connection_cache_type::key_type url) { SYNCHRONIZED; @@ -218,7 +226,7 @@ SQL_ConnectionPtr SQL_Driver_manager::ge return result; } - return 0; + return SQL_ConnectionPtr(0); } void SQL_Driver_manager::put_connection_to_cache( @@ -256,10 +264,9 @@ static void add_connection_to_status_cac row+=&url_without_login(pool, connection.get_url()); // time time_t time_used=connection.get_time_used(); - const char *unsafe_time_cstr=ctime(&time_used); + const char* unsafe_time_cstr=ctime(&time_used); int time_buf_size=strlen(unsafe_time_cstr); - char *safe_time_buf=(char *)pool.malloc(time_buf_size); - memcpy(safe_time_buf, unsafe_time_cstr, time_buf_size); + char *safe_time_buf=pool.copy(unsafe_time_cstr, time_buf_size); row+=new(pool) String(pool, safe_time_buf, time_buf_size); table+=&row;