tony2001 Thu Dec 25 08:54:51 2003 EDT Modified files: /php-src/ext/oci8 oci8.c php_oci8.h Log: workaround for possible ORA-22280 warning if buffers were not flushed
Index: php-src/ext/oci8/oci8.c diff -u php-src/ext/oci8/oci8.c:1.227 php-src/ext/oci8/oci8.c:1.228 --- php-src/ext/oci8/oci8.c:1.227 Wed Dec 24 10:01:54 2003 +++ php-src/ext/oci8/oci8.c Thu Dec 25 08:54:50 2003 @@ -22,7 +22,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: oci8.c,v 1.227 2003/12/24 15:01:54 tony2001 Exp $ */ +/* $Id: oci8.c,v 1.228 2003/12/25 13:54:50 tony2001 Exp $ */ /* TODO list: * @@ -200,6 +200,7 @@ static void _oci_column_hash_dtor(void *data); static void _oci_define_hash_dtor(void *data); static void _oci_bind_hash_dtor(void *data); +static void _oci_desc_flush_hash_dtor(void *data); static oci_connection *oci_get_conn(zval ** TSRMLS_DC); static oci_statement *oci_get_stmt(zval ** TSRMLS_DC); @@ -237,6 +238,50 @@ static int oci_lob_flush(oci_descriptor*, int); /* }}} */ +/* {{{ extension macros */ + +#define OCI_GET_STMT(statement,value) \ + statement = oci_get_stmt(value TSRMLS_CC); \ + if (statement == NULL) { \ + RETURN_FALSE; \ + } + +#define OCI_GET_CONN(connection,value) \ + connection = oci_get_conn(value TSRMLS_CC); \ + if (connection == NULL) { \ + RETURN_FALSE; \ + } + +#define OCI_GET_DESC(descriptor,index) \ + descriptor = oci_get_desc(index TSRMLS_CC); \ + if (descriptor == NULL) { \ + RETURN_FALSE; \ + } + +#ifdef PHP_OCI8_HAVE_COLLECTIONS +#define OCI_GET_COLL(collection,index) \ + collection = oci_get_coll(index TSRMLS_CC); \ + if (collection == NULL) { \ + RETURN_FALSE; \ + } +#endif + +#define IS_LOB_INTERNAL(lob) \ + if (lob->type != OCI_DTYPE_LOB) { \ + switch (lob->type) { \ + case OCI_DTYPE_FILE: \ + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "internal LOB was expected, FILE locator is given"); \ + break; \ + case OCI_DTYPE_ROWID: \ + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "internal LOB was expected, ROWID locator is given"); \ + break; \ + default: \ + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "internal LOB was expected, locator of unknown type is given"); \ + break; \ + } \ + RETURN_FALSE; \ + } +/* }}} */ /* {{{ extension function prototypes */ PHP_FUNCTION(oci_bind_by_name); @@ -313,48 +358,6 @@ PHP_FUNCTION(oci_collection_trim); #endif -#define OCI_GET_STMT(statement,value) \ - statement = oci_get_stmt(value TSRMLS_CC); \ - if (statement == NULL) { \ - RETURN_FALSE; \ - } - -#define OCI_GET_CONN(connection,value) \ - connection = oci_get_conn(value TSRMLS_CC); \ - if (connection == NULL) { \ - RETURN_FALSE; \ - } - -#define OCI_GET_DESC(descriptor,index) \ - descriptor = oci_get_desc(index TSRMLS_CC); \ - if (descriptor == NULL) { \ - RETURN_FALSE; \ - } - -#ifdef PHP_OCI8_HAVE_COLLECTIONS -#define OCI_GET_COLL(collection,index) \ - collection = oci_get_coll(index TSRMLS_CC); \ - if (collection == NULL) { \ - RETURN_FALSE; \ - } -#endif - -#define IS_LOB_INTERNAL(lob) \ - if (lob->type != OCI_DTYPE_LOB) { \ - switch (lob->type) { \ - case OCI_DTYPE_FILE: \ - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "internal LOB was expected, FILE locator is given"); \ - break; \ - case OCI_DTYPE_ROWID: \ - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "internal LOB was expected, ROWID locator is given"); \ - break; \ - default: \ - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "internal LOB was expected, locator of unknown type is given"); \ - break; \ - } \ - RETURN_FALSE; \ - } - /* }}} */ /* {{{ extension definition structures */ @@ -772,7 +775,7 @@ php_info_print_table_start(); php_info_print_table_row(2, "OCI8 Support", "enabled"); - php_info_print_table_row(2, "Revision", "$Revision: 1.227 $"); + php_info_print_table_row(2, "Revision", "$Revision: 1.228 $"); sprintf(buf, "%ld", num_persistent); php_info_print_table_row(2, "Active Persistent Links", buf); @@ -820,6 +823,20 @@ } /* }}} */ +/* {{{ _oci_desc_flush_hash_dtor() + */ + +static void +_oci_desc_flush_hash_dtor(void *data) +{ + oci_descriptor *descr = *((oci_descriptor **)data); + if (descr->buffering == 2 && (descr->type == OCI_DTYPE_LOB || descr->type == OCI_DTYPE_FILE)) { + oci_lob_flush(descr,OCI_LOB_BUFFER_FREE); + descr->buffering = 1; + } +} + +/* }}} */ /* {{{ _oci_bind_hash_dtor() */ static void @@ -944,7 +961,7 @@ zend_hash_destroy(statement->defines); efree(statement->defines); } - + oci_debug("END _oci_stmt_list_dtor: id=%d",statement->id); efree(statement); @@ -988,6 +1005,11 @@ /* close associated session when destructed */ zend_list_delete(connection->session->num); } + + if (connection->descriptors) { + zend_hash_destroy(connection->descriptors); + efree(connection->descriptors); + } if (connection->pError) { CALL_OCI(OCIHandleFree( @@ -1041,7 +1063,13 @@ { oci_descriptor *descr = (oci_descriptor *)rsrc->ptr; oci_debug("START _oci_descriptor_list_dtor: %d",descr->id); - + + /* flushing Lobs & Files with buffering enabled */ + if ((descr->type == OCI_DTYPE_FILE || descr->type == OCI_DTYPE_LOB) && descr->buffering == 2) { + oci_debug("descriptor #%d needs to be flushed. flushing..",descr->id); + oci_lob_flush(descr,OCI_LOB_BUFFER_FREE); + } + CALL_OCI(OCIDescriptorFree( descr->ocidescr, Z_TYPE_P(descr))); @@ -1248,8 +1276,7 @@ } /* }}} */ -/* {{{ oci_get_desc() */ - +/* {{{ oci_get_desc() */ static oci_descriptor *oci_get_desc(int ind TSRMLS_DC) { oci_descriptor *descriptor; @@ -1325,6 +1352,7 @@ default: php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown descriptor type %d.",Z_TYPE_P(descr)); + efree(descr); return 0; } @@ -1339,6 +1367,7 @@ ub4 error; error = oci_error(OCI(pError),"OCIDescriptorAlloc %d",OCI(error)); oci_handle_error(connection, error); + efree(descr); return 0; } @@ -1348,7 +1377,16 @@ descr->lob_size = -1; /* we should set it to -1 to know, that it's just not initialized */ descr->buffering = 0; /* buffering is off by default */ zend_list_addref(connection->id); + + if (descr->type == OCI_DTYPE_LOB || descr->type == OCI_DTYPE_FILE) { + /* add Lobs & Files to hash. we'll flush them ate the end */ + if (! connection->descriptors) { + ALLOC_HASHTABLE(connection->descriptors); + zend_hash_init(connection->descriptors, 13, NULL, _oci_desc_flush_hash_dtor, 0); + } + zend_hash_next_index_insert(connection->descriptors,&descr,sizeof(oci_descriptor *),NULL); + } oci_debug("oci_new_desc %d",descr->id); return descr; @@ -3234,7 +3272,7 @@ oci_statement *statement; oci_out_column *column; ub4 nrows = 1; - int i, used; + int i; if (ZEND_NUM_ARGS() > expected_args) { WRONG_PARAM_COUNT; @@ -5020,6 +5058,10 @@ OCI_GET_CONN(connection,conn); + if (connection->descriptors) { + zend_hash_apply(connection->descriptors,(apply_func_t) _oci_desc_flush_hash_dtor TSRMLS_CC); + } + oci_debug("<OCITransRollback"); CALL_OCI_RETURN(connection->error, OCITransRollback( @@ -5056,6 +5098,10 @@ OCI_GET_CONN(connection,conn); + if (connection->descriptors) { + zend_hash_apply(connection->descriptors,(apply_func_t) _oci_desc_flush_hash_dtor TSRMLS_CC); + } + oci_debug("<OCITransCommit"); CALL_OCI_RETURN(connection->error, OCITransCommit( Index: php-src/ext/oci8/php_oci8.h diff -u php-src/ext/oci8/php_oci8.h:1.31 php-src/ext/oci8/php_oci8.h:1.32 --- php-src/ext/oci8/php_oci8.h:1.31 Tue Dec 16 05:29:11 2003 +++ php-src/ext/oci8/php_oci8.h Thu Dec 25 08:54:50 2003 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_oci8.h,v 1.31 2003/12/16 10:29:11 phanto Exp $ */ +/* $Id: php_oci8.h,v 1.32 2003/12/25 13:54:50 tony2001 Exp $ */ #if HAVE_OCI8 # ifndef PHP_OCI8_H @@ -91,6 +91,7 @@ sword error; OCIError *pError; int needs_commit; + HashTable *descriptors; } oci_connection; typedef struct {
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php