51
51
} \
52
52
} while(0)
53
53
54
- static php_stream * oci_create_lob_stream (pdo_stmt_t * stmt , OCILobLocator * lob );
54
+ static php_stream * oci_create_lob_stream (zval * dbh , pdo_stmt_t * stmt , OCILobLocator * lob );
55
55
56
56
static int oci_stmt_dtor (pdo_stmt_t * stmt ) /* {{{ */
57
57
{
@@ -377,7 +377,7 @@ static int oci_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data *pa
377
377
* wanted to bind a lob locator into it from the query
378
378
* */
379
379
380
- stm = oci_create_lob_stream (stmt , (OCILobLocator * )P -> thing );
380
+ stm = oci_create_lob_stream (& stmt -> database_object_handle , stmt , (OCILobLocator * )P -> thing );
381
381
if (stm ) {
382
382
OCILobOpen (S -> H -> svc , S -> err , (OCILobLocator * )P -> thing , OCI_LOB_READWRITE );
383
383
php_stream_to_zval (stm , parameter );
@@ -614,6 +614,7 @@ struct _oci_lob_env {
614
614
typedef struct _oci_lob_env oci_lob_env ;
615
615
616
616
struct oci_lob_self {
617
+ zval dbh ;
617
618
pdo_stmt_t * stmt ;
618
619
pdo_oci_stmt * S ;
619
620
OCILobLocator * lob ;
@@ -666,10 +667,14 @@ static size_t oci_blob_read(php_stream *stream, char *buf, size_t count)
666
667
static int oci_blob_close (php_stream * stream , int close_handle )
667
668
{
668
669
struct oci_lob_self * self = (struct oci_lob_self * )stream -> abstract ;
669
- /* pdo_stmt_t *stmt = self->stmt; */
670
+ pdo_stmt_t * stmt = self -> stmt ;
670
671
671
672
if (close_handle ) {
673
+ zend_object * obj = & stmt -> std ;
674
+
672
675
OCILobClose (self -> E -> svc , self -> E -> err , self -> lob );
676
+ zval_ptr_dtor (& self -> dbh );
677
+ GC_REFCOUNT (obj )-- ;
673
678
efree (self -> E );
674
679
efree (self );
675
680
}
@@ -709,10 +714,12 @@ static php_stream_ops oci_blob_stream_ops = {
709
714
NULL
710
715
};
711
716
712
- static php_stream * oci_create_lob_stream (pdo_stmt_t * stmt , OCILobLocator * lob )
717
+ static php_stream * oci_create_lob_stream (zval * dbh , pdo_stmt_t * stmt , OCILobLocator * lob )
713
718
{
714
719
php_stream * stm ;
715
720
struct oci_lob_self * self = ecalloc (1 , sizeof (* self ));
721
+
722
+ ZVAL_COPY_VALUE (& self -> dbh , dbh );
716
723
self -> lob = lob ;
717
724
self -> offset = 1 ; /* 1-based */
718
725
self -> stmt = stmt ;
@@ -724,6 +731,10 @@ static php_stream *oci_create_lob_stream(pdo_stmt_t *stmt, OCILobLocator *lob)
724
731
stm = php_stream_alloc (& oci_blob_stream_ops , self , 0 , "r+b" );
725
732
726
733
if (stm ) {
734
+ zend_object * obj ;
735
+ obj = & stmt -> std ;
736
+ Z_ADDREF (self -> dbh );
737
+ GC_REFCOUNT (obj )++ ;
727
738
return stm ;
728
739
}
729
740
@@ -747,7 +758,7 @@ static int oci_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, size_t *len
747
758
748
759
if (C -> dtype == SQLT_BLOB || C -> dtype == SQLT_CLOB ) {
749
760
if (C -> data ) {
750
- * ptr = (char * )oci_create_lob_stream (stmt , (OCILobLocator * )C -> data );
761
+ * ptr = (char * )oci_create_lob_stream (& stmt -> database_object_handle , stmt , (OCILobLocator * )C -> data );
751
762
OCILobOpen (S -> H -> svc , S -> err , (OCILobLocator * )C -> data , OCI_LOB_READONLY );
752
763
}
753
764
* len = (size_t ) 0 ;
0 commit comments