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);
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_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 */
}
}
+/* }}} */
+/* {{{ _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() */
zend_hash_destroy(statement->defines);
efree(statement->defines);
}
-
+
oci_debug("END _oci_stmt_list_dtor: id=%d",statement->id);
efree(statement);
/* 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(
{
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)));
}
/* }}} */
-/* {{{ oci_get_desc() */
-
+/* {{{ oci_get_desc() */
static oci_descriptor *oci_get_desc(int ind TSRMLS_DC)
{
oci_descriptor *descriptor;
default:
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown descriptor type %d.",Z_TYPE_P(descr));
+ efree(descr);
return 0;
}
ub4 error;
error = oci_error(OCI(pError),"OCIDescriptorAlloc %d",OCI(error));
oci_handle_error(connection, error);
+ efree(descr);
return 0;
}
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;
oci_statement *statement;
oci_out_column *column;
ub4 nrows = 1;
- int i, used;
+ int i;
if (ZEND_NUM_ARGS() > expected_args) {
WRONG_PARAM_COUNT;
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(
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(