summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/pdo_oci/oci_statement.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/ext/pdo_oci/oci_statement.c b/ext/pdo_oci/oci_statement.c
index 868e69f77a..9c2e149935 100644
--- a/ext/pdo_oci/oci_statement.c
+++ b/ext/pdo_oci/oci_statement.c
@@ -51,7 +51,7 @@
} \
} while(0)
-static php_stream *oci_create_lob_stream(pdo_stmt_t *stmt, OCILobLocator *lob);
+static php_stream *oci_create_lob_stream(zval *dbh, pdo_stmt_t *stmt, OCILobLocator *lob);
static int oci_stmt_dtor(pdo_stmt_t *stmt) /* {{{ */
{
@@ -377,7 +377,7 @@ static int oci_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data *pa
* wanted to bind a lob locator into it from the query
* */
- stm = oci_create_lob_stream(stmt, (OCILobLocator*)P->thing);
+ stm = oci_create_lob_stream(&stmt->database_object_handle, stmt, (OCILobLocator*)P->thing);
if (stm) {
OCILobOpen(S->H->svc, S->err, (OCILobLocator*)P->thing, OCI_LOB_READWRITE);
php_stream_to_zval(stm, parameter);
@@ -614,6 +614,7 @@ struct _oci_lob_env {
typedef struct _oci_lob_env oci_lob_env;
struct oci_lob_self {
+ zval dbh;
pdo_stmt_t *stmt;
pdo_oci_stmt *S;
OCILobLocator *lob;
@@ -666,10 +667,14 @@ static size_t oci_blob_read(php_stream *stream, char *buf, size_t count)
static int oci_blob_close(php_stream *stream, int close_handle)
{
struct oci_lob_self *self = (struct oci_lob_self *)stream->abstract;
- /* pdo_stmt_t *stmt = self->stmt; */
+ pdo_stmt_t *stmt = self->stmt;
if (close_handle) {
+ zend_object *obj = &stmt->std;
+
OCILobClose(self->E->svc, self->E->err, self->lob);
+ zval_ptr_dtor(&self->dbh);
+ GC_REFCOUNT(obj)--;
efree(self->E);
efree(self);
}
@@ -709,10 +714,12 @@ static php_stream_ops oci_blob_stream_ops = {
NULL
};
-static php_stream *oci_create_lob_stream(pdo_stmt_t *stmt, OCILobLocator *lob)
+static php_stream *oci_create_lob_stream(zval *dbh, pdo_stmt_t *stmt, OCILobLocator *lob)
{
php_stream *stm;
struct oci_lob_self *self = ecalloc(1, sizeof(*self));
+
+ ZVAL_COPY_VALUE(&self->dbh, dbh);
self->lob = lob;
self->offset = 1; /* 1-based */
self->stmt = stmt;
@@ -724,6 +731,10 @@ static php_stream *oci_create_lob_stream(pdo_stmt_t *stmt, OCILobLocator *lob)
stm = php_stream_alloc(&oci_blob_stream_ops, self, 0, "r+b");
if (stm) {
+ zend_object *obj;
+ obj = &stmt->std;
+ Z_ADDREF(self->dbh);
+ GC_REFCOUNT(obj)++;
return stm;
}
@@ -747,7 +758,7 @@ static int oci_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, size_t *len
if (C->dtype == SQLT_BLOB || C->dtype == SQLT_CLOB) {
if (C->data) {
- *ptr = (char*)oci_create_lob_stream(stmt, (OCILobLocator*)C->data);
+ *ptr = (char*)oci_create_lob_stream(&stmt->database_object_handle, stmt, (OCILobLocator*)C->data);
OCILobOpen(S->H->svc, S->err, (OCILobLocator*)C->data, OCI_LOB_READONLY);
}
*len = (size_t) 0;