CVS update: php31/ext/odbc

From: Date: Mon, 14 Sep 1998 16:56:31 +0000
Subject: CVS update: php31/ext/odbc
Groups: php.dev 
Request: Send a blank email to php-dev+get-1065@lists.php.net to get a copy of this message
Date: Monday September 14, 1998 @ 12:56 Author: shane Update of /repository/php31/ext/odbc In directory asf:/u2/tmp/cvs-serv18848/ext/odbc Modified Files: unified_odbc.c Log Message: Hmm, several things I've been working on that I don't remember specifics of. mysql compiles with the latest windows stuff I've been working on with monty. odbc fixes from 3.0 tree adding gdlib to project (now that I have a reentrant version, still needs testing) Index: php31/ext/odbc/unified_odbc.c diff -c php31/ext/odbc/unified_odbc.c:2.12 php31/ext/odbc/unified_odbc.c:2.13 *** php31/ext/odbc/unified_odbc.c:2.12 Thu Sep 10 20:22:39 1998 --- php31/ext/odbc/unified_odbc.c Mon Sep 14 12:56:31 1998 *************** *** 31,40 **** /* This file is based on the Adabas D extension. * Adabas D will no longer be supported as separate module. */ #ifdef THREAD_SAFE #include "tls.h" #endif ! #ifndef MSVC5 #include "config.h" #include "build-defs.h" #endif --- 31,44 ---- /* This file is based on the Adabas D extension. * Adabas D will no longer be supported as separate module. */ + #define IS_EXT_MODULE + #if !PHP_31 + #undef THREAD_SAFE + #endif #ifdef THREAD_SAFE #include "tls.h" #endif ! #if !(WIN32|WINNT) #include "config.h" #include "build-defs.h" #endif *************** *** 42,61 **** #include "php.h" #include "internal_functions.h" ! #include "ext/standard/php3_string.h" #include "php3_unified_odbc.h" #include "head.h" #include "snprintf.h" - #if COMPILE_DL - #include "../phpdl.h" - #endif - #if HAVE_UODBC ! #define IS_EXT_MODULE #ifdef THREAD_SAFE ! MUTEX_T UODBC_MUTEX; DWORD UODBC_TLS; static int numthreads=0; --- 46,65 ---- #include "php.h" #include "internal_functions.h" ! #if PHP_31 ! # include "ext/standard/php3_string.h" ! #else ! # include "php3_string.h" ! #endif #include "php3_unified_odbc.h" #include "head.h" #include "snprintf.h" #if HAVE_UODBC ! #ifdef THREAD_SAFE ! void *UODBC_MUTEX; DWORD UODBC_TLS; static int numthreads=0; *************** *** 65,71 **** #define UODBC_GLOBAL(a) UODBC_GLOBALS->a ! #define UODBC_TLS_VARS UODBC_GLOBAL_STRUCT *PHP3_TLS_GET(UODBC_TLS,UODBC_GLOBALS); #else UODBC_MODULE PHP3_UODBC_MODULE; --- 69,76 ---- #define UODBC_GLOBAL(a) UODBC_GLOBALS->a ! #define UODBC_TLS_VARS \ ! UODBC_GLOBAL_STRUCT *UODBC_GLOBALS = TlsGetValue(UODBC_TLS); #else UODBC_MODULE PHP3_UODBC_MODULE; *************** *** 122,127 **** --- 127,133 ---- #if COMPILE_DL + #include "ext/phpdl.h" DLEXPORT php3_module_entry *get_module() { return &UODBC_MODULE_ENTRY; }; #endif *************** *** 208,221 **** HDBC foobar; RETCODE rc; #endif ! #ifdef THREAD_SAFE UODBC_GLOBAL_STRUCT *UODBC_GLOBALS; PHP3_MUTEX_ALLOC(UODBC_MUTEX); PHP3_MUTEX_LOCK(UODBC_MUTEX); numthreads++; if (numthreads==1){ if (!PHP3_TLS_PROC_STARTUP(UODBC_TLS)){ - OutputDebugString("ODBC TLS PROC FAILURE!\n"); PHP3_MUTEX_UNLOCK(UODBC_MUTEX); PHP3_MUTEX_FREE(UODBC_MUTEX); return FAILURE; --- 214,228 ---- HDBC foobar; RETCODE rc; #endif ! ! #if defined(THREAD_SAFE) UODBC_GLOBAL_STRUCT *UODBC_GLOBALS; + PHP3_MUTEX_ALLOC(UODBC_MUTEX); PHP3_MUTEX_LOCK(UODBC_MUTEX); numthreads++; if (numthreads==1){ if (!PHP3_TLS_PROC_STARTUP(UODBC_TLS)){ PHP3_MUTEX_UNLOCK(UODBC_MUTEX); PHP3_MUTEX_FREE(UODBC_MUTEX); return FAILURE; *************** *** 223,251 **** } PHP3_MUTEX_UNLOCK(UODBC_MUTEX); if(!PHP3_TLS_THREAD_INIT(UODBC_TLS,UODBC_GLOBALS,UODBC_GLOBAL_STRUCT)){ - OutputDebugString("ODBC TLS THREAD FAILURE!\n"); PHP3_MUTEX_FREE(UODBC_MUTEX); return FAILURE; } #endif SQLAllocEnv(&UODBC_GLOBAL(PHP3_UODBC_MODULE).henv); ! /* FIXME cfg_get_string(ODBC_INI_DEFAULTDB, &UODBC_GLOBAL(PHP3_UODBC_MODULE).defDB); cfg_get_string(ODBC_INI_DEFAULTUSER, &UODBC_GLOBAL(PHP3_UODBC_MODULE).defUser); cfg_get_string(ODBC_INI_DEFAULTPW, &UODBC_GLOBAL(PHP3_UODBC_MODULE).defPW); ! */ ! // if (cfg_get_long(ODBC_INI_ALLOWPERSISTENT,&UODBC_GLOBAL(PHP3_UODBC_MODULE).allow_persistent)== FAILURE) { UODBC_GLOBAL(PHP3_UODBC_MODULE).allow_persistent = -1; ! // } ! // if (cfg_get_long(ODBC_INI_MAXPERSISTENT, &UODBC_GLOBAL(PHP3_UODBC_MODULE).max_persistent)== FAILURE) { UODBC_GLOBAL(PHP3_UODBC_MODULE).max_persistent = -1; - // } - // if (cfg_get_long(ODBC_INI_MAXLINKS, &UODBC_GLOBAL(PHP3_UODBC_MODULE).max_links)== FAILURE) { UODBC_GLOBAL(PHP3_UODBC_MODULE).max_links = -1; ! // } UODBC_GLOBAL(PHP3_UODBC_MODULE).num_persistent = 0; UODBC_GLOBAL(PHP3_UODBC_MODULE).le_result = --- 230,270 ---- } PHP3_MUTEX_UNLOCK(UODBC_MUTEX); if(!PHP3_TLS_THREAD_INIT(UODBC_TLS,UODBC_GLOBALS,UODBC_GLOBAL_STRUCT)){ PHP3_MUTEX_FREE(UODBC_MUTEX); return FAILURE; } #endif + SQLAllocEnv(&UODBC_GLOBAL(PHP3_UODBC_MODULE).henv); ! ! #if !PHP_31 cfg_get_string(ODBC_INI_DEFAULTDB, &UODBC_GLOBAL(PHP3_UODBC_MODULE).defDB); cfg_get_string(ODBC_INI_DEFAULTUSER, &UODBC_GLOBAL(PHP3_UODBC_MODULE).defUser); cfg_get_string(ODBC_INI_DEFAULTPW, &UODBC_GLOBAL(PHP3_UODBC_MODULE).defPW); ! if (cfg_get_long(ODBC_INI_ALLOWPERSISTENT, ! &UODBC_GLOBAL(PHP3_UODBC_MODULE).allow_persistent) ! == FAILURE) { UODBC_GLOBAL(PHP3_UODBC_MODULE).allow_persistent = -1; ! } ! if (cfg_get_long(ODBC_INI_MAXPERSISTENT, ! &UODBC_GLOBAL(PHP3_UODBC_MODULE).max_persistent) ! == FAILURE) { ! UODBC_GLOBAL(PHP3_UODBC_MODULE).max_persistent = -1; ! } ! if (cfg_get_long(ODBC_INI_MAXLINKS, ! &UODBC_GLOBAL(PHP3_UODBC_MODULE).max_links) ! == FAILURE) { ! UODBC_GLOBAL(PHP3_UODBC_MODULE).max_links = -1; ! } ! #else ! UODBC_GLOBAL(PHP3_UODBC_MODULE).allow_persistent = -1; UODBC_GLOBAL(PHP3_UODBC_MODULE).max_persistent = -1; UODBC_GLOBAL(PHP3_UODBC_MODULE).max_links = -1; ! #endif ! UODBC_GLOBAL(PHP3_UODBC_MODULE).num_persistent = 0; UODBC_GLOBAL(PHP3_UODBC_MODULE).le_result = *************** *** 284,318 **** UODBC_GLOBAL(PHP3_UODBC_MODULE).defConn = -1; UODBC_GLOBAL(PHP3_UODBC_MODULE).num_links = UODBC_GLOBAL(PHP3_UODBC_MODULE).num_persistent; ! /* FIXME */ ! // if (cfg_get_long(ODBC_INI_DEFAULTLRL, &UODBC_GLOBAL(PHP3_UODBC_MODULE).defaultlrl)== FAILURE){ UODBC_GLOBAL(PHP3_UODBC_MODULE).defaultlrl = 4096; - // } - // if (cfg_get_long(ODBC_INI_DEFAULTBINMODE, &UODBC_GLOBAL(PHP3_UODBC_MODULE).defaultbinmode) == FAILURE){ UODBC_GLOBAL(PHP3_UODBC_MODULE).defaultbinmode = 1; ! // } ! return SUCCESS; } ! int PHP3_MSHUTDOWN_UODBC(void){ UODBC_TLS_VARS; #ifdef THREAD_SAFE - #if DEBUG - if(numthreads<0){ - /*ok this is a real problem!*/ - #if MSVC5 - char logmessage[80]; - snprintf(logmessage, 79, "%d:uodbc mshutdown numthreads error!\n", GetCurrentThreadId()); - OutputDebugString(logmessage); - #endif - return FAILURE; - } - #endif PHP3_TLS_THREAD_FREE(UODBC_GLOBALS); PHP3_MUTEX_LOCK(UODBC_MUTEX); numthreads--; ! if (numthreads<1) { PHP3_TLS_PROC_SHUTDOWN(UODBC_TLS); PHP3_MUTEX_UNLOCK(UODBC_MUTEX); PHP3_MUTEX_FREE(UODBC_MUTEX); --- 303,333 ---- UODBC_GLOBAL(PHP3_UODBC_MODULE).defConn = -1; UODBC_GLOBAL(PHP3_UODBC_MODULE).num_links = UODBC_GLOBAL(PHP3_UODBC_MODULE).num_persistent; ! #if PHP_31 UODBC_GLOBAL(PHP3_UODBC_MODULE).defaultlrl = 4096; UODBC_GLOBAL(PHP3_UODBC_MODULE).defaultbinmode = 1; ! #else ! if (cfg_get_long(ODBC_INI_DEFAULTLRL, &UODBC_GLOBAL(PHP3_UODBC_MODULE).defaultlrl) ! == FAILURE){ ! UODBC_GLOBAL(PHP3_UODBC_MODULE).defaultlrl = 4096; ! } ! if (cfg_get_long(ODBC_INI_DEFAULTBINMODE, &UODBC_GLOBAL(PHP3_UODBC_MODULE).defaultbinmode) == FAILURE){ ! UODBC_GLOBAL(PHP3_UODBC_MODULE).defaultbinmode = 1; ! } ! #endif return SUCCESS; } ! int PHP3_MSHUTDOWN_UODBC(void) ! { UODBC_TLS_VARS; + + SQLFreeEnv(UODBC_GLOBAL(PHP3_UODBC_MODULE).henv); #ifdef THREAD_SAFE PHP3_TLS_THREAD_FREE(UODBC_GLOBALS); PHP3_MUTEX_LOCK(UODBC_MUTEX); numthreads--; ! if (!numthreads) { PHP3_TLS_PROC_SHUTDOWN(UODBC_TLS); PHP3_MUTEX_UNLOCK(UODBC_MUTEX); PHP3_MUTEX_FREE(UODBC_MUTEX); *************** *** 324,330 **** } - void PHP3_INFO_UODBC(void) { #if !defined(COMPILE_DL) && defined(THREAD_SAFE) --- 339,344 ---- *************** *** 1546,1551 **** --- 1560,1571 ---- * connections get hashed up. Normal connections use existing pconnections. * Maybe this has to change with regard to transactions on pconnections? * Possibly set autocommit to on on request shutdown. + * + * We do have to hash non-persistent connections, and reuse connections. + * In the case where two connects were being made, without closing the first + * connect, access violations were occuring. This is because some of the + * "globals" in this module should actualy be per-connection variables. I + * simply fixed things to get them working for now. Shane */ void PHP3_UODBC_DO_CONNECT(INTERNAL_FUNCTION_PARAMETERS, int persistent) { *************** *** 1607,1625 **** hashed_len = _php3_sprintf(hashed_details, "uodbc_%s_%s_%s", db, uid, pwd); /* try to find if we already have this link in our persistent list, * no matter if it is to be persistent or not */ if (_php3_hash_find(plist, hashed_details, hashed_len + 1, ! (void **) &index_ptr) == FAILURE) { /* the link is not in the persistent list */ list_entry new_le, new_index_ptr; ! if (persistent) db_conn = (UODBC_CONNECTION *)malloc(sizeof(UODBC_CONNECTION)); ! else db_conn = (UODBC_CONNECTION *)emalloc(sizeof(UODBC_CONNECTION)); SQLAllocConnect(UODBC_GLOBAL(PHP3_UODBC_MODULE).henv, &db_conn->hdbc); #if HAVE_SOLID --- 1627,1651 ---- hashed_len = _php3_sprintf(hashed_details, "uodbc_%s_%s_%s", db, uid, pwd); + /* FIXME the idea of checking to see if our connection is already persistent + is good, but it adds a lot of overhead to non-persistent connections. We + should look and see if we can fix that somehow */ /* try to find if we already have this link in our persistent list, * no matter if it is to be persistent or not */ if (_php3_hash_find(plist, hashed_details, hashed_len + 1, ! (void **) &index_ptr) == FAILURE && ! (!persistent && _php3_hash_find(list, hashed_details, hashed_len + 1, ! (void **) &index_ptr) == FAILURE)) { /* the link is not in the persistent list */ list_entry new_le, new_index_ptr; ! if (persistent) { db_conn = (UODBC_CONNECTION *)malloc(sizeof(UODBC_CONNECTION)); ! } else { db_conn = (UODBC_CONNECTION *)emalloc(sizeof(UODBC_CONNECTION)); + } SQLAllocConnect(UODBC_GLOBAL(PHP3_UODBC_MODULE).henv, &db_conn->hdbc); #if HAVE_SOLID *************** *** 1644,1650 **** return_value->value.lval = php3_plist_insert(db_conn, UODBC_GLOBAL(PHP3_UODBC_MODULE).le_pconn); new_index_ptr.ptr = (void *) return_value->value.lval; ! #ifdef COMPILE_DL new_index_ptr.type = _php3_le_index_ptr(); #else new_index_ptr.type = le_index_ptr; --- 1670,1676 ---- return_value->value.lval = php3_plist_insert(db_conn, UODBC_GLOBAL(PHP3_UODBC_MODULE).le_pconn); new_index_ptr.ptr = (void *) return_value->value.lval; ! #ifdef THREAD_SAFE new_index_ptr.type = _php3_le_index_ptr(); #else new_index_ptr.type = le_index_ptr; *************** *** 1659,1666 **** } UODBC_GLOBAL(PHP3_UODBC_MODULE).num_persistent++; } else { ! /* non persistent, simply add to list */ ! return_value->value.lval = php3_list_insert(db_conn, UODBC_GLOBAL(PHP3_UODBC_MODULE).le_conn); } UODBC_GLOBAL(PHP3_UODBC_MODULE).num_links++; --- 1685,1708 ---- } UODBC_GLOBAL(PHP3_UODBC_MODULE).num_persistent++; } else { ! new_le.type = UODBC_GLOBAL(PHP3_UODBC_MODULE).le_conn; ! new_le.ptr = db_conn; ! return_value->value.lval = ! php3_list_insert(db_conn, UODBC_GLOBAL(PHP3_UODBC_MODULE).le_conn); ! new_index_ptr.ptr = (void *) return_value->value.lval; ! #ifdef THREAD_SAFE ! new_index_ptr.type = _php3_le_index_ptr(); ! #else ! new_index_ptr.type = le_index_ptr; ! #endif ! if (_php3_hash_update(list,hashed_details,hashed_len + 1,(void *) &new_index_ptr, ! sizeof(list_entry),NULL)==FAILURE) { ! SQLDisconnect(db_conn->hdbc); ! SQLFreeConnect(db_conn->hdbc); ! free(db_conn); ! efree(hashed_details); ! RETURN_FALSE; ! } } UODBC_GLOBAL(PHP3_UODBC_MODULE).num_links++; *************** *** 1668,1684 **** } else { int type; ! /* the link is already in the persistent list */ ! #ifdef COMPILE_DL ! if (index_ptr->type != _php3_le_index_ptr()) { #else ! if (index_ptr->type != le_index_ptr) { #endif efree(hashed_details); RETURN_FALSE; } id = (int) index_ptr->ptr; db_conn = (UODBC_CONNECTION *)php3_plist_find(id, &type); /* FIXME test if the connection is dead */ /* For Adabas D and local db connections, a reconnect is performed --- 1710,1733 ---- } else { int type; ! /* we are already connected */ ! #ifdef THREAD_SAFE ! if (index_ptr->type != _php3_le_index_ptr()) { #else ! if (index_ptr->type != le_index_ptr) { #endif efree(hashed_details); RETURN_FALSE; } id = (int) index_ptr->ptr; + + /* first see if there is a persistent connection and use it, + else, if we are making a non-persistent connect, check our + non-persistent list */ db_conn = (UODBC_CONNECTION *)php3_plist_find(id, &type); + if(!db_conn && !persistent) + db_conn = (UODBC_CONNECTION *)php3_list_find(id, &type); + /* FIXME test if the connection is dead */ /* For Adabas D and local db connections, a reconnect is performed -- PHP Development Mailing List http://www.php.net/ To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net For help: php-dev-help@lists.php.net

« previous php.dev (#1065) next »