Skip to content

Commit bc6b88e

Browse files
committed
Add REF CURSOR support. Result Set tidy ups. Renumber constants.
1 parent 322e447 commit bc6b88e

File tree

11 files changed

+241
-124
lines changed

11 files changed

+241
-124
lines changed

lib/oracledb.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,16 @@ try {
3131

3232
var oracledb_ins = new oracledb.Oracledb();
3333

34-
oracledb_ins.STRING = 1;
35-
oracledb_ins.NUMBER = 2;
36-
oracledb_ins.DATE = 3;
34+
oracledb_ins.STRING = 2001;
35+
oracledb_ins.NUMBER = 2002;
36+
oracledb_ins.DATE = 2003;
37+
oracledb_ins.CURSOR = 2004;
3738

38-
oracledb_ins.ARRAY = 1;
39-
oracledb_ins.OBJECT = 2;
39+
oracledb_ins.BIND_IN = 3001;
40+
oracledb_ins.BIND_INOUT = 3002;
41+
oracledb_ins.BIND_OUT = 3003;
4042

41-
oracledb_ins.BIND_IN = 1;
42-
oracledb_ins.BIND_INOUT = 2;
43-
oracledb_ins.BIND_OUT = 3;
43+
oracledb_ins.ARRAY = 4001;
44+
oracledb_ins.OBJECT = 4002;
4445

4546
module.exports = oracledb_ins;

src/dpi/include/dpiConn.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class Conn
6767
virtual void action(const string &action) = 0;
6868

6969
// methods
70-
virtual Stmt* getStmt (const string &sql) = 0;
70+
virtual Stmt* getStmt (const string &sql="") = 0;
7171

7272
virtual void commit() = 0;
7373

src/dpi/include/dpiStmt.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ typedef enum
8686
DpiClob = 112,
8787
DpiBlob = 113,
8888
DpiBfile = 114,
89+
DpiRSet = 116,
8990
DpiYearMonth = 182, /* internal only */
9091
DpiDaySecond = 183, /* internal only */
9192
DpiTimestamp = 187, /* internal only */

src/dpi/src/dpiConnImpl.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,6 @@ Stmt* ConnImpl::getStmt (const string &sql)
414414
}
415415

416416

417-
418417
/*****************************************************************************/
419418
/*
420419
DESCRIPTION

src/dpi/src/dpiStmtImpl.cpp

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,27 @@ StmtImpl::StmtImpl (EnvImpl *env, OCIEnv *envh, ConnImpl *conn,
8888

8989
try : conn_(conn), errh_(NULL), svch_(svch),
9090
stmth_(NULL), numCols_ (0),meta_(NULL), stmtType_ (DpiStmtUnknown),
91-
isReturning_(false), isReturningSet_(false)
91+
isReturning_(false), isReturningSet_(false), refCursor_(false)
9292
{
9393
// create an OCIError object for this execution
9494
ociCallEnv (OCIHandleAlloc ((void *)envh, (dvoid **)&errh_,
9595
OCI_HTYPE_ERROR, 0, (dvoid **)0), envh);
9696

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+
}
102112
}
103113
catch (...)
104114
{
@@ -240,7 +250,9 @@ void StmtImpl::bind (unsigned int pos, unsigned short type, void *buf,
240250
OCIBind *b = (OCIBind *)0;
241251

242252
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,
244256
(cb ? NULL : ind),
245257
(cb ? NULL : bufLen),
246258
NULL, 0, NULL,
@@ -285,7 +297,9 @@ void StmtImpl::bind (const unsigned char *name, int nameLen,
285297
OCIBind *b = (OCIBind *)0;
286298

287299
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,
289303
(cb ? NULL : ind),
290304
(cb ? NULL : bufLen),
291305
NULL, 0, NULL,
@@ -518,7 +532,12 @@ void StmtImpl::cleanup ()
518532
}
519533
if ( stmth_)
520534
{
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+
522541
stmth_ = NULL;
523542
}
524543
if ( errh_)

src/dpi/src/dpiStmtImpl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ class StmtImpl : public Stmt
112112
dvoid **bufpp, ub4 **alenp, ub1 *piecep,
113113
dvoid **indpp, ub2 **rcodepp );
114114

115-
116115
private:
117116
void cleanup ();
118117

@@ -131,6 +130,7 @@ class StmtImpl : public Stmt
131130
DpiStmtType stmtType_; // Statement Type (Query, DML, ... )
132131
bool isReturning_; // Does the stmt has RETURNING INTO clause?
133132
bool isReturningSet_; // Has isReturning_ flag queried & set.
133+
bool refCursor_; // refCursor or not.
134134
};
135135

136136

0 commit comments

Comments
 (0)