use reference counting for emulating child<->parent (cursor<->connection) relationships.
authorThies C. Arntzen <thies@php.net>
Tue, 5 Oct 1999 16:06:54 +0000 (16:06 +0000)
committerThies C. Arntzen <thies@php.net>
Tue, 5 Oct 1999 16:06:54 +0000 (16:06 +0000)
ChangeLog
ext/oci8/oci8.c
ext/oci8/php3_oci8.h

index 4641d4008b92e2522669a63fbe257d500ff86560..710d3b776e2fba7219118e8dd7cdc1e3f9bf68d5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,7 @@ PHP 4.0 CHANGE LOG                                                    ChangeLog
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 
 ?? ?? 1999, Version 4.0 Beta 3
+- OCI8 connections are now kept open as long as they are referenced (Thies)
 - Cleaned up Directory-Module (Thies)
 - Small fix in Ora_Close (Thies)
 - Ported range() and shuffle() from PHP3 to PHP4 (Andrei)
index 583f6c3a084d7bfcea55be1d5e4c18d6f357f5f5..8160cd6d10481b479630522ba600b60839fe6a61 100644 (file)
@@ -306,9 +306,6 @@ static void php_oci_init_globals(php_oci_globals *oci_globals)
        OCI(server) = malloc(sizeof(HashTable));
        zend_hash_init(OCI(server), 13, NULL, NULL, 1); 
 
-       OCI(conns) = malloc(sizeof(HashTable));
-       zend_hash_init(OCI(conns), 13, NULL, NULL, 1);
-
        OCIEnvInit(&OCI(pEnv), OCI_DEFAULT, 0, NULL);
        OCIHandleAlloc(OCI(pEnv), 
                                   (dvoid **)&OCI(pError),
@@ -336,9 +333,6 @@ PHP_MINIT_FUNCTION(oci)
        OCI(server) = malloc(sizeof(HashTable));
        zend_hash_init(OCI(server), 13, NULL, NULL, 1); 
 
-       OCI(conns) = malloc(sizeof(HashTable));
-       zend_hash_init(OCI(conns), 13, NULL, NULL, 1);
-
        OCIEnvInit(&OCI(pEnv), OCI_DEFAULT, 0, NULL);
        OCIHandleAlloc(OCI(pEnv), 
                                   (dvoid **)&OCI(pError),
@@ -451,11 +445,9 @@ PHP_MSHUTDOWN_FUNCTION(oci)
 
        zend_hash_destroy(OCI(user));
        zend_hash_destroy(OCI(server));
-       zend_hash_destroy(OCI(conns));
 
        free(OCI(user));
        free(OCI(server));
-       free(OCI(conns));
 
        OCIHandleFree((dvoid *)OCI(pEnv), OCI_HTYPE_ENV);
 
@@ -547,16 +539,12 @@ static int
 _oci_column_dtor(void *data)
 {      
        oci_out_column *column = (oci_out_column *) data;
-       oci_connection *db_conn;
-       OCILS_FETCH();
 
        oci_debug("START _oci_column_dtor: %s",column->name);
 
        if (column->data) {
                if (column->is_descr) {
-                       if (zend_hash_find(OCI(conns),(void*)&(column->statement->conn),sizeof(void*),(void **)&db_conn) == SUCCESS) {
-                               zend_hash_index_del(column->statement->conn->descriptors,(int) column->data);
-                       }
+                       zend_hash_index_del(column->statement->conn->descriptors,(int) column->data);
                } else {
                        if (column->data) {
                                efree(column->data);
@@ -575,15 +563,11 @@ _oci_column_dtor(void *data)
 
 /* }}} */
 /* {{{ _oci_statement_dtor() */
-
 static void
 _oci_statement_dtor(oci_statement *statement)
 {
-       if (! statement) {
-               return;
-       }
-
-       oci_debug("_oci_statement_dtor: id=%d last_query=\"%s\"",statement->id,SAFE_STRING(statement->last_query));
+       oci_debug("START _oci_statement_dtor: id=%d last_query=\"%s\"",statement->id,SAFE_STRING(statement->last_query));
 
        if (statement->pStmt) {
                OCIHandleFree(statement->pStmt, OCI_HTYPE_STMT);
@@ -614,6 +598,10 @@ _oci_statement_dtor(oci_statement *statement)
                efree(statement->defines);
        }
 
+       zend_list_delete(statement->conn->id); /* delete one ref from the connection */
+
+       oci_debug("END _oci_statement_dtor: id=%d",statement->id);
+
        efree(statement);
 }
 
@@ -627,12 +615,8 @@ _oci_connection_dtor(oci_connection *connection)
           as the connection is "only" a in memory service context we do not disconnect from oracle.
        */
 
-       OCILS_FETCH();
-
        oci_debug("START _oci_connection_dtor: id=%d",connection->id);
 
-       zend_hash_del(OCI(conns),(void*)&connection,sizeof(void*));
-
        if (connection->descriptors) {
                zend_hash_destroy(connection->descriptors);
                efree(connection->descriptors);
@@ -961,6 +945,8 @@ static oci_statement *oci_parse(oci_connection *connection, char *query, int len
                           statement->id,
                           statement->conn->id);
 
+       zend_list_addref(statement->conn->id);
+
        return statement;
 }
 
@@ -2153,7 +2139,7 @@ static void oci_do_connect(INTERNAL_FUNCTION_PARAMETERS,int persistent,int exclu
        */
 
 
-       connection->id = php3_list_insert(connection, le_conn);
+       connection->id = zend_list_insert(connection, le_conn);
 
        connection->descriptors = emalloc(sizeof(HashTable));
        if (!connection->descriptors ||
@@ -2165,15 +2151,13 @@ static void oci_do_connect(INTERNAL_FUNCTION_PARAMETERS,int persistent,int exclu
 
        oci_debug("oci_do_connect: id=%d",connection->id);
 
-       zend_hash_add(OCI(conns),(void*)&connection,sizeof(void*),(void*)&connection,sizeof(void*),NULL);
-
        RETURN_RESOURCE(connection->id);
        
  CLEANUP:
        oci_debug("oci_do_connect: FAILURE -> CLEANUP called");
 
        if (connection->id) {
-               php3_list_delete(connection->id);
+               zend_list_delete(connection->id);
        } else {
                _oci_connection_dtor(connection);
        }
@@ -3155,7 +3139,7 @@ PHP_FUNCTION(ocifreestatement)
 
        OCI_GET_STMT(statement,stmt);
 
-       php3_list_delete(statement->id);
+       zend_list_delete(statement->id);
 
        RETURN_TRUE;
 }
@@ -3182,7 +3166,7 @@ PHP_FUNCTION(ocilogoff)
 
        zend_hash_apply(list,(int (*)(void *))_stmt_cleanup);
 
-       if (php3_list_delete(connection->id) == SUCCESS) {
+       if (zend_list_delete(connection->id) == SUCCESS) {
                RETURN_TRUE;
        } else {
                RETURN_FALSE;
index d6d2e0d55fa57f0950ce3f9ff5b795e70128fd2c..3df40bcdd064b1c0773752f144430a96614eeb45 100644 (file)
@@ -168,8 +168,6 @@ typedef struct {
        int user_num;
        HashTable *user;
 
-       HashTable *conns;
-
     OCIEnv *pEnv;
 } php_oci_globals;