@@ -88,17 +88,27 @@ StmtImpl::StmtImpl (EnvImpl *env, OCIEnv *envh, ConnImpl *conn,
88
88
89
89
try : conn_(conn), errh_(NULL ), svch_(svch),
90
90
stmth_(NULL ), numCols_ (0 ),meta_(NULL ), stmtType_ (DpiStmtUnknown),
91
- isReturning_(false ), isReturningSet_(false )
91
+ isReturning_(false ), isReturningSet_(false ), refCursor_( false )
92
92
{
93
93
// create an OCIError object for this execution
94
94
ociCallEnv (OCIHandleAlloc ((void *)envh, (dvoid **)&errh_,
95
95
OCI_HTYPE_ERROR, 0 , (dvoid **)0 ), envh);
96
96
97
- // Prepare OCIStmt object with given sql statement.
98
- ociCall (OCIStmtPrepare2 (svch_, &stmth_, errh_, (oratext *)sql.data (),
99
- (ub4)sql.length (), NULL , 0 , OCI_NTV_SYNTAX,
100
- OCI_DEFAULT),
101
- errh_);
97
+ if (!sql.empty ())
98
+ {
99
+ // Prepare OCIStmt object with given sql statement.
100
+ ociCall (OCIStmtPrepare2 (svch_, &stmth_, errh_, (oratext *)sql.data (),
101
+ (ub4)sql.length (), NULL , 0 , OCI_NTV_SYNTAX,
102
+ OCI_DEFAULT),
103
+ errh_);
104
+ }
105
+ else
106
+ {
107
+ // to build empty stmt object used for ref cursors.
108
+ ociCall (OCIHandleAlloc ((void *)envh, (dvoid **)&stmth_,
109
+ OCI_HTYPE_STMT,0 , (dvoid **)0 ), errh_);
110
+ refCursor_ = true ;
111
+ }
102
112
}
103
113
catch (...)
104
114
{
@@ -240,7 +250,9 @@ void StmtImpl::bind (unsigned int pos, unsigned short type, void *buf,
240
250
OCIBind *b = (OCIBind *)0 ;
241
251
242
252
ociCall (DPIBINDBYPOS (stmth_, &b, errh_, pos,
243
- (cb ? NULL : buf), bufSize, type,
253
+ (cb ? NULL : (type==DpiRSet) ?
254
+ (void *)&(((StmtImpl*)buf)->stmth_ ) : buf),
255
+ (type == DpiRSet) ? 0 : bufSize, type,
244
256
(cb ? NULL : ind),
245
257
(cb ? NULL : bufLen),
246
258
NULL , 0 , NULL ,
@@ -285,7 +297,9 @@ void StmtImpl::bind (const unsigned char *name, int nameLen,
285
297
OCIBind *b = (OCIBind *)0 ;
286
298
287
299
ociCall (DPIBINDBYNAME (stmth_, &b, errh_, name, nameLen,
288
- (cb ? NULL : buf), bufSize, type,
300
+ (cb ? NULL : (type == DpiRSet) ?
301
+ (void *)&((StmtImpl*)buf)->stmth_ : buf),
302
+ (type == DpiRSet) ? 0 : bufSize, type,
289
303
(cb ? NULL : ind),
290
304
(cb ? NULL : bufLen),
291
305
NULL , 0 , NULL ,
@@ -518,7 +532,12 @@ void StmtImpl::cleanup ()
518
532
}
519
533
if ( stmth_)
520
534
{
521
- ociCall ( OCIStmtRelease (stmth_, errh_, NULL , 0 , OCI_DEFAULT), errh_ );
535
+ // Release not called for ref cursor.
536
+ if ( refCursor_ )
537
+ OCIHandleFree ( stmth_, OCI_HTYPE_STMT );
538
+ else
539
+ ociCall ( OCIStmtRelease (stmth_, errh_, NULL , 0 , OCI_DEFAULT), errh_ );
540
+
522
541
stmth_ = NULL ;
523
542
}
524
543
if ( errh_)
0 commit comments