cvs: /php4/ext/odbc php_odbc.c php_odbc.h

From: Date: Thu, 07 Oct 1999 18:50:11 +0000
Subject: cvs: /php4/ext/odbc php_odbc.c php_odbc.h
Groups: php.version4 
Request: Send a blank email to php-version4+get-5317@lists.php.net to get a copy of this message
kara Thu Oct 7 14:50:11 1999 EDT Modified files: /php4/ext/odbc php_odbc.c php_odbc.h Log: Made henv a real global var. Seems to work basically when multithreaded Index: php4/ext/odbc/php_odbc.c diff -u php4/ext/odbc/php_odbc.c:1.4 php4/ext/odbc/php_odbc.c:1.5 --- php4/ext/odbc/php_odbc.c:1.4 Sat Sep 25 07:30:28 1999 +++ php4/ext/odbc/php_odbc.c Thu Oct 7 14:49:41 1999 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_odbc.c,v 1.4 1999/09/25 11:30:28 kara Exp $ */ +/* $Id: php_odbc.c,v 1.5 1999/10/07 18:49:41 kara Exp $ */ #if COMPILE_DL #include "dl/phpdl.h" @@ -54,6 +54,13 @@ void odbc_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent); static int le_result, le_conn, le_pconn; + +#if defined( HAVE_DB2 ) || defined( HAVE_UNIXODBC ) + SQLHANDLE henv; +#else + HENV henv; +#endif + function_entry odbc_functions[] = { PHP_FE(odbc_setoption, NULL) @@ -134,7 +141,7 @@ } if(res->stmt){ #if HAVE_SOLID - SQLTransact(ODBCG(henv), res->conn_ptr->hdbc, + SQLTransact(henv, res->conn_ptr->hdbc, (UWORD)SQL_COMMIT); #endif SQLFreeStmt(res->stmt,SQL_DROP); @@ -293,6 +300,7 @@ PHP_MINIT_FUNCTION(odbc) { ELS_FETCH(); + ODBCLS_D; #ifdef SQLANY_BUG HDBC foobar; RETCODE rc; @@ -300,25 +308,26 @@ #ifdef ZTS odbc_globals_id = ts_allocate_id(sizeof(php_odbc_globals), php_odbc_init_globals, NULL); + odbc_globals = ts_resource(odbc_globals_id); #else ODBCG(num_persistent) = 0; #endif REGISTER_INI_ENTRIES(); - SQLAllocEnv(&ODBCG(henv)); + SQLAllocEnv(&henv); le_result = register_list_destructors(_free_odbc_result, NULL); le_conn = register_list_destructors(_close_odbc_conn, NULL); le_pconn = register_list_destructors(NULL, _close_odbc_pconn); odbc_module_entry.type = type; - SQLAllocEnv(&ODBCG(henv)); + SQLAllocEnv(&henv); #ifdef SQLANY_BUG /* Make a dumb connection to avoid crash on SQLFreeEnv(), * then release it immediately. * This is required for SQL Anywhere 5.5.00 on QNX 4.24 at least. * The SQLANY_BUG should be defined in CFLAGS. */ - if(SQLAllocConnect(ODBCG(henv), &foobar) != SQL_SUCCESS){ + if(SQLAllocConnect(henv, &foobar) != SQL_SUCCESS){ ODBC_SQL_ERROR(SQL_NULL_HDBC, SQL_NULL_HSTMT, "SQLAllocConnect"); }else{ rc = SQLConnect(foobar, ODBCG(defDB), SQL_NTS, ODBCG(defUser), @@ -420,7 +429,7 @@ ODBCLS_FETCH(); UNREGISTER_INI_ENTRIES(); - SQLFreeEnv(ODBCG(henv)); + SQLFreeEnv(henv); return SUCCESS; } @@ -456,9 +465,9 @@ SDWORD error; /* Not used */ char errormsg[255]; SWORD errormsgsize; /* Not used */ - ODBC_TLS_VARS; + ODBCLS_FETCH(); - SQLError(ODBCG(henv), conn, stmt, state, + SQLError(henv, conn, stmt, state, &error, errormsg, sizeof(errormsg)-1, &errormsgsize); if(func){ php_error(E_WARNING, "SQL error: %s, SQL state %s in %s", @@ -502,7 +511,8 @@ int i; SWORD colnamelen; /* Not used */ SDWORD displaysize; - + ODBCLS_FETCH(); + result->values = (odbc_result_value *) emalloc(sizeof(odbc_result_value)*result->numcols); @@ -569,7 +579,7 @@ conn = (odbc_connection *) zend_fetch_resource_ex(pv_conn, -1, "ODBC connection", 2, le_conn, le_pconn); ZEND_VERIFY_RESOURCE(conn); - rc = SQLTransact(ODBCG(henv), conn->hdbc, (UWORD)((type)?SQL_COMMIT:SQL_ROLLBACK)); + rc = SQLTransact(henv, conn->hdbc, (UWORD)((type)?SQL_COMMIT:SQL_ROLLBACK)); if(rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO){ ODBC_SQL_ERROR(conn->hdbc, SQL_NULL_HSTMT, "SQLTransact"); RETURN_FALSE; @@ -875,9 +885,9 @@ SDWORD error; /* Not used */ char errormsg[255]; SWORD errormsgsize; /* Not used */ - ODBC_TLS_VARS; + ODBCLS_FETCH(); - SQLError(ODBCG(henv), result->conn_ptr->hdbc, + SQLError(henv, result->conn_ptr->hdbc, result->stmt, state, &error, errormsg, sizeof(errormsg)-1, &errormsgsize); if(!strncmp(state,"S1015",5)){ @@ -1564,7 +1574,7 @@ *conn = (odbc_connection *)pemalloc(sizeof(odbc_connection), persistent); (*conn)->persistent = persistent; - SQLAllocConnect(ODBCG(henv), &((*conn)->hdbc)); + SQLAllocConnect(henv, &((*conn)->hdbc)); #if HAVE_SOLID SQLSetConnectOption((*conn)->hdbc, SQL_TRANSLATE_OPTION, Index: php4/ext/odbc/php_odbc.h diff -u php4/ext/odbc/php_odbc.h:1.3 php4/ext/odbc/php_odbc.h:1.4 --- php4/ext/odbc/php_odbc.h:1.3 Thu Sep 23 10:46:35 1999 +++ php4/ext/odbc/php_odbc.h Thu Oct 7 14:49:41 1999 @@ -28,7 +28,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_odbc.h,v 1.3 1999/09/23 14:46:35 lurcher Exp $ */ +/* $Id: php_odbc.h,v 1.4 1999/10/07 18:49:41 kara Exp $ */ #ifndef _PHP_ODBC_H #define _PHP_ODBC_H @@ -39,6 +39,10 @@ #define FAR #endif +#ifdef ZTS +#include "TSRM.h" +#endif + /* checking in the same order as in configure.in */ #if HAVE_SOLID /* Solid Server */ @@ -220,11 +224,6 @@ } odbc_result; typedef struct { -#if defined( HAVE_DB2 ) || defined( HAVE_UNIXODBC ) - SQLHANDLE henv; -#else - HENV henv; -#endif char *defDB; char *defUser; char *defPW; @@ -263,7 +262,6 @@ # define ODBCLS_CC , ODBCLS_C # define ODBCG(v) (odbc_globals->v) # define ODBCLS_FETCH() php_odbc_globals *odbc_globals = ts_resource(odbc_globals_id) -# define ODBC_TLS_VARS char *globals; ODBCLS_FETCH(); globals = (char *)odbc_globals; #else # define ODBCLS_D # define ODBCLS_DC @@ -271,7 +269,6 @@ # define ODBCLS_CC # define ODBCG(v) (odbc_globals.v) # define ODBCLS_FETCH() -# define ODBC_TLS_VARS char *globals = (char *)&odbc_globals extern ZEND_API php_odbc_globals odbc_globals; #endif

« previous php.version4 (#5317) next »