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

From: Date: Mon, 13 Mar 2000 15:23:18 +0000
Subject: cvs: /php4/ext/odbc php_odbc.c php_odbc.h
Groups: php.version4 
Request: Send a blank email to php-version4+get-12057@lists.php.net to get a copy of this message
kara Mon Mar 13 07:23:18 2000 EDT Modified files: /php4/ext/odbc php_odbc.c php_odbc.h Log: odbc_close() and odbc_close_all() working again Index: php4/ext/odbc/php_odbc.c diff -u php4/ext/odbc/php_odbc.c:1.37 php4/ext/odbc/php_odbc.c:1.38 --- php4/ext/odbc/php_odbc.c:1.37 Sun Mar 12 09:18:21 2000 +++ php4/ext/odbc/php_odbc.c Mon Mar 13 07:22:47 2000 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_odbc.c,v 1.37 2000/03/12 17:18:21 sas Exp $ */ +/* $Id: php_odbc.c,v 1.38 2000/03/13 15:22:47 kara Exp $ */ #if COMPILE_DL #include "dl/phpdl.h" @@ -512,6 +512,7 @@ int odbc_bindcols(odbc_result *result) { + RETCODE rc; int i; SWORD colnamelen; /* Not used */ SDWORD displaysize; @@ -530,12 +531,12 @@ result->binmode = ODBCG(defaultbinmode); for(i = 0; i < result->numcols; i++) { - SQLColAttributes(result->stmt, (UWORD)(i+1), SQL_COLUMN_NAME, + rc = SQLColAttributes(result->stmt, (UWORD)(i+1), SQL_COLUMN_NAME, result->values[i].name, sizeof(result->values[i].name), &colnamelen, 0); - SQLColAttributes(result->stmt, (UWORD)(i+1), SQL_COLUMN_TYPE, + rc = SQLColAttributes(result->stmt, (UWORD)(i+1), SQL_COLUMN_TYPE, NULL, 0, NULL, &result->values[i].coltype); /* Don't bind LONG / BINARY columns, so that fetch behaviour can @@ -558,10 +559,10 @@ break; #endif /* HAVE_ADABAS */ default: - SQLColAttributes(result->stmt, (UWORD)(i+1), SQL_COLUMN_DISPLAY_SIZE, + rc = SQLColAttributes(result->stmt, (UWORD)(i+1), SQL_COLUMN_DISPLAY_SIZE, NULL, 0, NULL, &displaysize); result->values[i].value = (char *)emalloc(displaysize + 1); - SQLBindCol(result->stmt, (UWORD)(i+1), SQL_C_CHAR, result->values[i].value, + rc = SQLBindCol(result->stmt, (UWORD)(i+1), SQL_C_CHAR, result->values[i].value, displaysize + 1, &result->values[i].vallen); break; } @@ -591,22 +592,53 @@ RETURN_TRUE; } +static int _close_pconn_with_id(list_entry *le, int *id) +{ + + if(le->type == le_pconn && (((odbc_connection *)(le->ptr))->id == *id)){ + return 1; + }else{ + return 0; + } +} /* 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) { void *ptr; int type; - int i, nument = zend_hash_next_free_element(&EG(regular_list)); - + int i; + int nument; + ELS_FETCH(); + + nument = zend_hash_next_free_element(&EG(regular_list)); + + /* Loop through list and close all statements */ for(i = 1; i < nument; i++) { ptr = zend_list_find(i, &type); - if (ptr && (type == le_conn || type == le_pconn)) { + if (ptr && (type == le_result)){ zend_list_delete(i); } } + + /* Second loop through list, now close all connections */ + nument = zend_hash_next_free_element(&EG(regular_list)); + + for(i = 1; i < nument; i++) { + ptr = zend_list_find(i, &type); + if (ptr){ + if(type == le_conn){ + zend_list_delete(i); + }else if(type == le_pconn){ + zend_list_delete(i); + /* Delete the persistent connection */ + zend_hash_apply_with_argument(&EG(persistent_list), + (int (*)(void *, void *)) _close_pconn_with_id, (void *) &i); + } + } + } } /* }}} */ @@ -1717,7 +1749,7 @@ persistent = 0; } - len = strlen(db) + strlen(uid) + strlen(pwd) + sizeof(ODBC_TYPE) - 1 + 5; + len = strlen(db) + strlen(uid) + strlen(pwd) + sizeof(ODBC_TYPE) + 5; hashed_details = emalloc(len); if (hashed_details == NULL) { @@ -1799,7 +1831,7 @@ } } } - /* db_conn->id = 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; @@ -1851,16 +1883,44 @@ PHP_FUNCTION(odbc_close) { pval **pv_conn; + void *ptr; odbc_connection *conn; + odbc_result *res; + int nument; + int i; + int type; + int is_pconn = 0; ODBCLS_FETCH(); + ELS_FETCH(); if (zend_get_parameters_ex(1, &pv_conn) == FAILURE) { WRONG_PARAM_COUNT; } - ZEND_FETCH_RESOURCE2(conn, odbc_connection *, pv_conn, -1, "ODBC-Link", le_conn, le_pconn); + conn = (odbc_connection *) zend_fetch_resource(pv_conn, -1, "ODBC-Link", NULL, 1, le_conn); + if(!conn){ + ZEND_FETCH_RESOURCE(conn, odbc_connection *, pv_conn, -1, "ODBC-Link", le_pconn); + is_pconn = 1; + } + + nument = zend_hash_next_free_element(&EG(regular_list)); + + for(i = 1; i < nument; i++){ + ptr = zend_list_find(i, &type); + if(ptr && (type == le_result)){ + res = (odbc_result *)ptr; + if(res->conn_ptr == conn){ + zend_list_delete(i); + } + } + } zend_list_delete((*pv_conn)->value.lval); + + if(is_pconn){ + zend_hash_apply_with_argument(&EG(persistent_list), + (int (*)(void *, void *)) _close_pconn_with_id, (void *) &((*pv_conn)->value.lval)); + } } /* }}} */ Index: php4/ext/odbc/php_odbc.h diff -u php4/ext/odbc/php_odbc.h:1.18 php4/ext/odbc/php_odbc.h:1.19 --- php4/ext/odbc/php_odbc.h:1.18 Sat Mar 11 17:03:23 2000 +++ php4/ext/odbc/php_odbc.h Mon Mar 13 07:22:47 2000 @@ -28,7 +28,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_odbc.h,v 1.18 2000/03/12 01:03:23 codelion Exp $ */ +/* $Id: php_odbc.h,v 1.19 2000/03/13 15:22:47 kara Exp $ */ #ifndef _PHP_ODBC_H #define _PHP_ODBC_H @@ -215,7 +215,6 @@ HENV henv; HDBC hdbc; #endif -/* int open;*/ int id; int persistent; } odbc_connection;

« previous php.version4 (#12057) next »