Skip to content

Commit

Permalink
Add REF CURSOR support. Result Set tidy ups. Renumber constants.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjbj committed Jul 20, 2015
1 parent 322e447 commit bc6b88e
Show file tree
Hide file tree
Showing 11 changed files with 241 additions and 124 deletions.
17 changes: 9 additions & 8 deletions lib/oracledb.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,16 @@ try {

var oracledb_ins = new oracledb.Oracledb();

oracledb_ins.STRING = 1;
oracledb_ins.NUMBER = 2;
oracledb_ins.DATE = 3;
oracledb_ins.STRING = 2001;
oracledb_ins.NUMBER = 2002;
oracledb_ins.DATE = 2003;
oracledb_ins.CURSOR = 2004;

oracledb_ins.ARRAY = 1;
oracledb_ins.OBJECT = 2;
oracledb_ins.BIND_IN = 3001;
oracledb_ins.BIND_INOUT = 3002;
oracledb_ins.BIND_OUT = 3003;

oracledb_ins.BIND_IN = 1;
oracledb_ins.BIND_INOUT = 2;
oracledb_ins.BIND_OUT = 3;
oracledb_ins.ARRAY = 4001;
oracledb_ins.OBJECT = 4002;

module.exports = oracledb_ins;
2 changes: 1 addition & 1 deletion src/dpi/include/dpiConn.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class Conn
virtual void action(const string &action) = 0;

// methods
virtual Stmt* getStmt (const string &sql) = 0;
virtual Stmt* getStmt (const string &sql="") = 0;

virtual void commit() = 0;

Expand Down
1 change: 1 addition & 0 deletions src/dpi/include/dpiStmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ typedef enum
DpiClob = 112,
DpiBlob = 113,
DpiBfile = 114,
DpiRSet = 116,
DpiYearMonth = 182, /* internal only */
DpiDaySecond = 183, /* internal only */
DpiTimestamp = 187, /* internal only */
Expand Down
1 change: 0 additions & 1 deletion src/dpi/src/dpiConnImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,6 @@ Stmt* ConnImpl::getStmt (const string &sql)
}



/*****************************************************************************/
/*
DESCRIPTION
Expand Down
37 changes: 28 additions & 9 deletions src/dpi/src/dpiStmtImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,27 @@ StmtImpl::StmtImpl (EnvImpl *env, OCIEnv *envh, ConnImpl *conn,

try : conn_(conn), errh_(NULL), svch_(svch),
stmth_(NULL), numCols_ (0),meta_(NULL), stmtType_ (DpiStmtUnknown),
isReturning_(false), isReturningSet_(false)
isReturning_(false), isReturningSet_(false), refCursor_(false)
{
// create an OCIError object for this execution
ociCallEnv (OCIHandleAlloc ((void *)envh, (dvoid **)&errh_,
OCI_HTYPE_ERROR, 0, (dvoid **)0), envh);

// Prepare OCIStmt object with given sql statement.
ociCall (OCIStmtPrepare2 (svch_, &stmth_, errh_, (oratext *)sql.data(),
(ub4)sql.length(), NULL, 0, OCI_NTV_SYNTAX,
OCI_DEFAULT),
errh_);
if(!sql.empty())
{
// Prepare OCIStmt object with given sql statement.
ociCall (OCIStmtPrepare2 (svch_, &stmth_, errh_, (oratext *)sql.data(),
(ub4)sql.length(), NULL, 0, OCI_NTV_SYNTAX,
OCI_DEFAULT),
errh_);
}
else
{
// to build empty stmt object used for ref cursors.
ociCall (OCIHandleAlloc ((void *)envh, (dvoid **)&stmth_,
OCI_HTYPE_STMT,0, (dvoid **)0), errh_);
refCursor_ = true;
}
}
catch (...)
{
Expand Down Expand Up @@ -240,7 +250,9 @@ void StmtImpl::bind (unsigned int pos, unsigned short type, void *buf,
OCIBind *b = (OCIBind *)0;

ociCall (DPIBINDBYPOS (stmth_, &b, errh_, pos,
(cb ? NULL : buf), bufSize, type,
(cb ? NULL : (type==DpiRSet) ?
(void *)&(((StmtImpl*)buf)->stmth_) : buf),
(type == DpiRSet) ? 0 : bufSize, type,
(cb ? NULL : ind),
(cb ? NULL : bufLen),
NULL, 0, NULL,
Expand Down Expand Up @@ -285,7 +297,9 @@ void StmtImpl::bind (const unsigned char *name, int nameLen,
OCIBind *b = (OCIBind *)0;

ociCall (DPIBINDBYNAME (stmth_, &b, errh_, name, nameLen,
(cb ? NULL : buf), bufSize, type,
(cb ? NULL : (type == DpiRSet) ?
(void *)&((StmtImpl*)buf)->stmth_: buf),
(type == DpiRSet) ? 0 : bufSize, type,
(cb ? NULL : ind),
(cb ? NULL : bufLen),
NULL, 0, NULL,
Expand Down Expand Up @@ -518,7 +532,12 @@ void StmtImpl::cleanup ()
}
if ( stmth_)
{
ociCall ( OCIStmtRelease (stmth_, errh_, NULL, 0, OCI_DEFAULT), errh_ );
// Release not called for ref cursor.
if ( refCursor_ )
OCIHandleFree ( stmth_, OCI_HTYPE_STMT );
else
ociCall ( OCIStmtRelease (stmth_, errh_, NULL, 0, OCI_DEFAULT), errh_ );

stmth_ = NULL;
}
if ( errh_)
Expand Down
2 changes: 1 addition & 1 deletion src/dpi/src/dpiStmtImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ class StmtImpl : public Stmt
dvoid **bufpp, ub4 **alenp, ub1 *piecep,
dvoid **indpp, ub2 **rcodepp );


private:
void cleanup ();

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


Expand Down
Loading

0 comments on commit bc6b88e

Please sign in to comment.