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

From: Date: Wed, 23 Feb 2000 16:34:38 +0000
Subject: cvs: /php4/ext/odbc php_odbc.c php_odbc.h
Groups: php.version4 
Request: Send a blank email to php-version4+get-10744@lists.php.net to get a copy of this message
kara Wed Feb 23 08:34:38 2000 EDT Modified files: /php4/ext/odbc php_odbc.c php_odbc.h Log: uodbc now uses zend's reference system. The crashes on request shutdown should be gone. Index: php4/ext/odbc/php_odbc.c diff -u php4/ext/odbc/php_odbc.c:1.30 php4/ext/odbc/php_odbc.c:1.31 --- php4/ext/odbc/php_odbc.c:1.30 Wed Feb 23 08:26:10 2000 +++ php4/ext/odbc/php_odbc.c Wed Feb 23 08:34:08 2000 @@ -18,16 +18,19 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_odbc.c,v 1.30 2000/02/23 16:26:10 eschmid Exp $ */ +/* $Id: php_odbc.c,v 1.31 2000/02/23 16:34:08 kara Exp $ */ #if COMPILE_DL #include "dl/phpdl.h" #endif #include "php.h" -#include "php_globals.h" -#include "ext/standard/php_standard.h" +#include "php_globals.h" +#include "ext/standard/info.h" +#include "ext/standard/php_string.h" +#include "ext/standard/php_standard.h" #include "php_odbc.h" +#include "php_globals.h" #if HAVE_UODBC @@ -129,14 +132,6 @@ DLEXPORT zend_module_entry *get_module(void) { return &odbc_module_entry; }; #endif -static int _odbc_stmt_cleanup(list_entry *le) -{ - if(le->type == le_result){ - return 1; - } - return 0; -} - static void _free_odbc_result(odbc_result *res) { int i; @@ -156,9 +151,10 @@ (UWORD)SQL_COMMIT); #endif SQLFreeStmt(res->stmt,SQL_DROP); -#if !defined( HAVE_IBMDB2 ) && !defined( HAVE_UNIXODBC ) - res->stmt = NULL; -#endif + /* We don't want the connection to be closed after the last statment has been closed + * Connections will be closed on shutdown + * zend_list_delete(res->conn_ptr->id); + */ } efree(res); } @@ -184,7 +180,6 @@ { ODBCLS_FETCH(); - conn->open = 0; SQLDisconnect(conn->hdbc); SQLFreeConnect(conn->hdbc); SQLFreeEnv(conn->henv); @@ -410,32 +405,12 @@ } -#if 0 -static void _php_odbc_shutdown(void *data) -{ - ELS_FETCH(); - - /* Close all statements before connection */ - - /* this is not the nice way of doing it - we should use reference counting - of the parent handles */ - - zend_hash_apply(&EG(regular_list), (int (*)(void *)) _odbc_stmt_cleanup); -} -#endif - - PHP_RINIT_FUNCTION(odbc) { ODBCLS_FETCH(); ODBCG(defConn) = -1; ODBCG(num_links) = ODBCG(num_persistent); - - /* This should no longer be necessary, as hash_apply() is reentrant - * php_register_pre_request_shutdown(_php_odbc_shutdown, NULL); - */ - return SUCCESS; } @@ -449,7 +424,6 @@ ODBCLS_FETCH(); UNREGISTER_INI_ENTRIES(); - /*SQLFreeEnv(henv);*/ return SUCCESS; } @@ -615,6 +589,7 @@ } /* Main User Functions */ +/* XXX This one needs rework, it won't work if there are active statements */ /* {{{ proto void odbc_close_all(void) Close all ODBC connections */ PHP_FUNCTION(odbc_close_all) @@ -705,9 +680,11 @@ } else { result->values = NULL; } + result->id = zend_list_insert(result, le_result); + zend_list_addref(conn->id); result->conn_ptr = conn; result->fetched = 0; - ZEND_REGISTER_RESOURCE(return_value, result, le_result); + RETURN_RESOURCE(result->id); } /* }}} */ @@ -1032,9 +1009,12 @@ } else { result->values = NULL; } + result->id = zend_list_insert(result, le_result); + zend_list_addref(conn->id); result->conn_ptr = conn; result->fetched = 0; - ZEND_REGISTER_RESOURCE(return_value, result, le_result); + + RETURN_RESOURCE(result->id); } /* }}} */ @@ -1571,7 +1551,7 @@ } ZEND_FETCH_RESOURCE(result, odbc_result *, pv_res, -1, "ODBC result", le_result); - zend_list_delete((*pv_res)->value.lval); + zend_list_delete(result->id); RETURN_TRUE; } @@ -1662,7 +1642,7 @@ pefree((*conn), persistent); return FALSE; } - (*conn)->open = 1; +/* (*conn)->open = 1;*/ return TRUE; } /* Persistent connections: two list-types le_pconn, le_conn and a plist @@ -1786,6 +1766,7 @@ } ODBCG(num_persistent)++; ODBCG(num_links)++; + db_conn->id = ZEND_REGISTER_RESOURCE(return_value, db_conn, le_pconn); } else { /* found connection */ if (le->type != le_pconn) { RETURN_FALSE; @@ -1815,7 +1796,7 @@ } } } - ZEND_REGISTER_RESOURCE(return_value, db_conn, le_pconn); + /* db_conn->id = ZEND_REGISTER_RESOURCE(return_value, db_conn, le_pconn); */ } else { /* non persistent */ list_entry *index_ptr, new_index_ptr; @@ -1848,13 +1829,14 @@ efree(hashed_details); RETURN_FALSE; } - ZEND_REGISTER_RESOURCE(return_value, db_conn, le_conn); + db_conn->id = ZEND_REGISTER_RESOURCE(return_value, db_conn, le_conn); new_index_ptr.ptr = (void *) return_value->value.lval; new_index_ptr.type = le_index_ptr; if (zend_hash_update(&EG(regular_list), hashed_details, hashed_len + 1, (void *) &new_index_ptr, sizeof(list_entry), NULL) == FAILURE) { efree(hashed_details); RETURN_FALSE; + /* XXX Free Connection */ } ODBCG(num_links)++; } Index: php4/ext/odbc/php_odbc.h diff -u php4/ext/odbc/php_odbc.h:1.14 php4/ext/odbc/php_odbc.h:1.15 --- php4/ext/odbc/php_odbc.h:1.14 Sun Jan 2 07:59:01 2000 +++ php4/ext/odbc/php_odbc.h Wed Feb 23 08:34:08 2000 @@ -28,17 +28,17 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_odbc.h,v 1.14 2000/01/02 15:59:01 kara Exp $ */ +/* $Id: php_odbc.h,v 1.15 2000/02/23 16:34:08 kara Exp $ */ #ifndef _PHP_ODBC_H #define _PHP_ODBC_H #if HAVE_UODBC -#ifndef MSVC5 +/*#ifndef MSVC5 #define FAR #endif - +*/ #ifdef ZTS #include "TSRM.h" #endif @@ -214,7 +214,8 @@ HENV henv; HDBC hdbc; #endif - int open; +/* int open;*/ + int id; int persistent; } odbc_connection; @@ -231,6 +232,7 @@ #else HSTMT stmt; #endif + int id; odbc_result_value *values; SWORD numcols; SWORD numparams;

« previous php.version4 (#10744) next »