Skip to content

Commit 32b80ec

Browse files
committed
More Result Set code and a new test
1 parent 7dc2f72 commit 32b80ec

File tree

10 files changed

+193
-167
lines changed

10 files changed

+193
-167
lines changed

src/dpi/include/dpiStmt.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ class Stmt
146146
// properties
147147
virtual DpiStmtType stmtType() const = 0;
148148

149+
// If NJS layer doesn't set any value, default prefetch is done by OCI.
149150
virtual void prefetchRows ( int prefetchRows ) = 0;
150151

151152
virtual bool isDML() const = 0 ;

src/njs/src/njsConnection.cpp

Lines changed: 68 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ NAN_METHOD(Connection::Execute)
343343
executeBaton->maxRows = connection->oracledb_->getMaxRows();
344344
executeBaton->prefetchRows = connection->oracledb_->getPrefetchRows();
345345
executeBaton->outFormat = connection->oracledb_->getOutFormat();
346-
executeBaton->autoCommit = connection->oracledb_->getAutoCommit();
346+
executeBaton->autoCommit = connection->oracledb_->getAutoCommit();
347347
executeBaton->dpienv = connection->oracledb_->getDpiEnv();
348348
executeBaton->dpiconn = connection->dpiconn_;
349349
executeBaton->njsconn = connection;
@@ -412,16 +412,16 @@ void Connection::ProcessOptions (_NAN_METHOD_ARGS, unsigned int index,
412412
if(args[index]->IsObject() && !args[index]->IsArray())
413413
{
414414
options = args[index]->ToObject();
415-
NJS_GET_UINT_FROM_JSON ( executeBaton->maxRows, executeBaton->error,
416-
options, "maxRows", 2, exitProcessOptions );
417-
NJS_GET_UINT_FROM_JSON ( executeBaton->prefetchRows, executeBaton->error,
418-
options, "prefetchRows", 2, exitProcessOptions );
419-
NJS_GET_UINT_FROM_JSON ( executeBaton->outFormat, executeBaton->error,
420-
options, "outFormat", 2, exitProcessOptions );
421-
NJS_GET_BOOL_FROM_JSON ( executeBaton->getRS, executeBaton->error,
422-
options, "resultSet", 2, exitProcessOptions );
423-
NJS_GET_BOOL_FROM_JSON ( executeBaton->autoCommit, executeBaton->error,
424-
options, "autoCommit", 2, exitProcessOptions );
415+
NJS_GET_UINT_FROM_JSON ( executeBaton->maxRows, executeBaton->error,
416+
options, "maxRows", 2, exitProcessOptions );
417+
NJS_GET_UINT_FROM_JSON ( executeBaton->prefetchRows, executeBaton->error,
418+
options, "prefetchRows", 2, exitProcessOptions );
419+
NJS_GET_UINT_FROM_JSON ( executeBaton->outFormat, executeBaton->error,
420+
options, "outFormat", 2, exitProcessOptions );
421+
NJS_GET_BOOL_FROM_JSON ( executeBaton->getRS, executeBaton->error,
422+
options, "resultSet", 2, exitProcessOptions );
423+
NJS_GET_BOOL_FROM_JSON ( executeBaton->autoCommit, executeBaton->error,
424+
options, "autoCommit", 2, exitProcessOptions );
425425
}
426426
else
427427
{
@@ -740,11 +740,12 @@ void Connection::Async_Execute (uv_work_t *req)
740740
executeBaton->dpistmt->execute(0, executeBaton->autoCommit);
741741
const dpi::MetaData* meta = executeBaton->dpistmt->getMetaData();
742742
executeBaton->numCols = executeBaton->dpistmt->numCols();
743-
executeBaton->columnNames = new std::string[executeBaton->numCols];
744-
Connection::metaData( executeBaton->columnNames, meta,
743+
executeBaton->columnNames = new std::string[executeBaton->numCols];
744+
Connection::CopyMetaData( executeBaton->columnNames, meta,
745745
executeBaton->numCols );
746746
if( executeBaton->getRS ) goto exitAsyncExecute;
747-
Connection::GetDefines(executeBaton, meta, executeBaton->numCols);
747+
Connection::DoDefines(executeBaton, meta, executeBaton->numCols);
748+
Connection::DoFetch(executeBaton);
748749
}
749750
else
750751
{
@@ -845,7 +846,9 @@ void Connection::PrepareAndBind (eBaton* executeBaton)
845846
executeBaton->st = executeBaton->dpistmt->stmtType ();
846847
executeBaton->stmtIsReturning = executeBaton->dpistmt->isReturning ();
847848

848-
if(executeBaton->getRS && executeBaton->prefetchRows > -1)
849+
// prefetch is set by user, pass it to DPI.
850+
if( executeBaton->getRS &&
851+
executeBaton->prefetchRows > NJS_PREFETCH_ROWS_NOT_SET )
849852
executeBaton->dpistmt->prefetchRows(executeBaton->prefetchRows);
850853

851854
if(!executeBaton->binds.empty())
@@ -955,81 +958,97 @@ void Connection::PrepareAndBind (eBaton* executeBaton)
955958
/*****************************************************************************/
956959
/*
957960
DESCRIPTION
958-
get meta data into baton
961+
copy column names from meta data to the string array passed as parameter.
959962
960963
PARAMETERS:
961-
string arrat, metaData, numCols
964+
string array - column names
965+
metaData - metaData info from DPI
966+
numCols - number of columns
962967
*/
963-
void Connection::metaData ( std::string* names, const dpi::MetaData* meta,
964-
unsigned int numCols )
968+
void Connection::CopyMetaData ( std::string* names, const dpi::MetaData* meta,
969+
unsigned int numCols )
965970
{
966-
for (unsigned int i = 0; i < numCols; i++)
971+
for (unsigned int col = 0; col < numCols; col++)
967972
{
968-
names[i] = std::string( (const char*)meta[i].colName,
969-
meta[i].colNameLen );
973+
names[col] = std::string( (const char*)meta[col].colName,
974+
meta[col].colNameLen );
970975
}
971976
}
972977

973978
/*****************************************************************************/
974979
/*
975980
DESCRIPTION
976-
Allocate defines buffer for query output.
977-
Call DPI define and fetch.
981+
Allocate defines buffer for query output and do fetch.
982+
Call DPI define.
978983
979984
PARAMETERS:
980985
eBaton struct
981986
*/
982-
void Connection::GetDefines ( eBaton* executeBaton, const dpi::MetaData* meta,
983-
unsigned int numCols )
987+
void Connection::DoDefines ( eBaton* executeBaton, const dpi::MetaData* meta,
988+
unsigned int numCols )
984989
{
985990
Define *defines = new Define[numCols];
986991

987-
for (unsigned int i = 0; i < numCols; i++)
992+
for (unsigned int col = 0; col < numCols; col++)
988993
{
989-
switch(meta[i].dbType)
994+
switch(meta[col].dbType)
990995
{
991996
case dpi::DpiNumber :
992997
case dpi::DpiBinaryFloat :
993998
case dpi::DpiBinaryDouble :
994-
defines[i].fetchType = dpi::DpiDouble;
995-
defines[i].maxSize = sizeof(double);
996-
defines[i].buf = (double *)malloc(defines[i].maxSize*executeBaton->maxRows);
999+
defines[col].fetchType = dpi::DpiDouble;
1000+
defines[col].maxSize = sizeof(double);
1001+
defines[col].buf = (double *)malloc(defines[col].maxSize*executeBaton->maxRows);
9971002
break;
9981003
case dpi::DpiVarChar :
9991004
case dpi::DpiFixedChar :
1000-
defines[i].fetchType = DpiVarChar;
1001-
defines[i].maxSize = meta[i].dbSize;
1002-
defines[i].buf = (char *)malloc(defines[i].maxSize*executeBaton->maxRows);
1005+
defines[col].fetchType = DpiVarChar;
1006+
defines[col].maxSize = meta[col].dbSize;
1007+
defines[col].buf = (char *)malloc(defines[col].maxSize*executeBaton->maxRows);
10031008
break;
10041009
case dpi::DpiDate :
10051010
case dpi::DpiTimestamp:
10061011
case dpi::DpiTimestampLTZ:
1007-
defines[i].dttmarr = executeBaton->dpienv->getDateTimeArray (
1012+
defines[col].dttmarr = executeBaton->dpienv->getDateTimeArray (
10081013
executeBaton->dpistmt->getError () );
1009-
defines[i].fetchType = DpiTimestampLTZ;
1010-
defines[i].maxSize = meta[i].dbSize;
1011-
defines[i].extbuf = defines[i].dttmarr->init(executeBaton->maxRows);
1014+
defines[col].fetchType = DpiTimestampLTZ;
1015+
defines[col].maxSize = meta[col].dbSize;
1016+
defines[col].extbuf = defines[col].dttmarr->init(executeBaton->maxRows);
10121017
break;
10131018
default :
10141019
executeBaton->error = NJSMessages::getErrorMsg(errUnsupportedDatType);
10151020
return;
10161021
break;
10171022
}
1018-
defines[i].ind = (short*)malloc (sizeof(short)*(executeBaton->maxRows));
1019-
defines[i].len = (DPI_BUFLEN_TYPE *)malloc(sizeof(DPI_BUFLEN_TYPE)*
1023+
defines[col].ind = (short*)malloc (sizeof(short)*(executeBaton->maxRows));
1024+
defines[col].len = (DPI_BUFLEN_TYPE *)malloc(sizeof(DPI_BUFLEN_TYPE)*
10201025
executeBaton->maxRows);
10211026

1022-
executeBaton->dpistmt->define(i+1, defines[i].fetchType,
1023-
(defines[i].buf) ? defines[i].buf : defines[i].extbuf,
1024-
defines[i].maxSize, defines[i].ind, defines[i].len);
1027+
executeBaton->dpistmt->define(col+1, defines[col].fetchType,
1028+
(defines[col].buf) ? defines[col].buf : defines[col].extbuf,
1029+
defines[col].maxSize, defines[col].ind, defines[col].len);
10251030
}
1031+
executeBaton->defines = defines;
1032+
executeBaton->numCols = numCols;
1033+
}
1034+
1035+
/*****************************************************************************/
1036+
/*
1037+
DESCRIPTION
1038+
Fetch rows into defines buffer for query output.
1039+
Call DPI fetch.
1040+
1041+
PARAMETERS:
1042+
eBaton struct
1043+
*/
1044+
void Connection::DoFetch (eBaton* executeBaton)
1045+
{
10261046
executeBaton->dpistmt->fetch(executeBaton->maxRows);
1027-
executeBaton->defines = defines;
1028-
executeBaton->numCols = numCols;
10291047
executeBaton->rowsFetched = executeBaton->dpistmt->rowsFetched();
1030-
Connection::descr2Dbl (executeBaton->defines, numCols,
1031-
executeBaton->rowsFetched,
1032-
executeBaton->getRS);
1048+
Connection::Descr2Dbl ( executeBaton->defines,
1049+
executeBaton->numCols,
1050+
executeBaton->rowsFetched,
1051+
executeBaton->getRS );
10331052
}
10341053

10351054
/*****************************************************************************/
@@ -1040,7 +1059,7 @@ void Connection::GetDefines ( eBaton* executeBaton, const dpi::MetaData* meta,
10401059
PARAMETERS:
10411060
Define struct, numCols
10421061
*/
1043-
void Connection::descr2Dbl( Define* defines, unsigned int numCols,
1062+
void Connection::Descr2Dbl( Define* defines, unsigned int numCols,
10441063
unsigned int rowsFetched, bool getRS )
10451064
{
10461065
for (unsigned int col = 0; col < numCols; col ++ )

src/njs/src/njsConnection.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ typedef struct eBaton
177177
}
178178
if( columnNames )
179179
delete [] columnNames;
180-
if( defines && !getRS )
180+
if( defines && !getRS ) // To reuse fetch Buffers of ResultSet
181181
{
182182
for( unsigned int i=0; i<numCols; i++ )
183183
{
@@ -201,10 +201,11 @@ class Connection: public ObjectWrap
201201
static Handle<Value> GetRows (eBaton* executeBaton);
202202
static Handle<Value> GetMetaData (std::string* columnNames,
203203
unsigned int numCols);
204-
static void GetDefines ( eBaton* executeBaton, const dpi::MetaData*,
205-
unsigned int numCols );
206-
static void metaData ( std::string*, const dpi::MetaData*, unsigned int );
207-
static void descr2Dbl ( Define* defines, unsigned int numCols,
204+
static void DoDefines ( eBaton* executeBaton, const dpi::MetaData*,
205+
unsigned int numCols );
206+
static void DoFetch (eBaton* executeBaton);
207+
static void CopyMetaData ( std::string*, const dpi::MetaData*, unsigned int );
208+
static void Descr2Dbl ( Define* defines, unsigned int numCols,
208209
unsigned int rowsFetched, bool getRS );
209210
bool getIsValid() { return isValid_; }
210211

src/njs/src/njsMessages.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static const char *errMsg[] =
5353
"NJS-016: buffer is too small for OUT binds",
5454
"NJS-017: concurrent operations on resultSet are not allowed",
5555
"NJS-018: invalid result set",
56-
"NJS-019: getResultSet set for non-query execution",
56+
"NJS-019: resultSet cannot be true for non-queries",
5757
};
5858

5959
string NJSMessages::getErrorMsg ( NJSErrorType err, ... )

src/njs/src/njsOracle.cpp

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,12 @@
5858
//peristent Oracledb class handle
5959
Persistent<FunctionTemplate> Oracledb::oracledbTemplate_s;
6060

61-
#define MAX_ROWS 100
62-
#define STMT_CACHE_SIZE 30
63-
#define POOL_MIN 0
64-
#define POOL_MAX 4
65-
#define POOL_INCR 1
66-
#define POOL_TIMEOUT 60
67-
#define PREFETCH_ROWS -1
61+
#define NJS_MAX_ROWS 100
62+
#define NJS_STMT_CACHE_SIZE 30
63+
#define NJS_POOL_MIN 0
64+
#define NJS_POOL_MAX 4
65+
#define NJS_POOL_INCR 1
66+
#define NJS_POOL_TIMEOUT 60
6867

6968
/*****************************************************************************/
7069
/*
@@ -75,16 +74,16 @@ Oracledb::Oracledb()
7574
{
7675
dpienv_ = dpi::Env::createEnv();
7776
outFormat_ = ROWS_ARRAY;
78-
maxRows_ = MAX_ROWS;
79-
autoCommit_ = false;
80-
stmtCacheSize_ = STMT_CACHE_SIZE;
81-
poolMax_ = POOL_MAX;
82-
poolMin_ = POOL_MIN;
83-
poolIncrement_ = POOL_INCR;
84-
poolTimeout_ = POOL_TIMEOUT;
85-
prefetchRows_ = PREFETCH_ROWS;
77+
maxRows_ = NJS_MAX_ROWS;
78+
autoCommit_ = false;
79+
stmtCacheSize_ = NJS_STMT_CACHE_SIZE;
80+
poolMax_ = NJS_POOL_MAX;
81+
poolMin_ = NJS_POOL_MIN;
82+
poolIncrement_ = NJS_POOL_INCR;
83+
poolTimeout_ = NJS_POOL_TIMEOUT;
84+
prefetchRows_ = NJS_PREFETCH_ROWS_NOT_SET;
8685
connClass_ = "";
87-
externalAuth_ = false;
86+
externalAuth_ = false;
8887
}
8988

9089
/*****************************************************************************/
@@ -112,7 +111,6 @@ void Oracledb::Init(Handle<Object> target)
112111
NanScope();
113112

114113
Local<FunctionTemplate> temp = NanNew<FunctionTemplate>(New);
115-
//Local<FunctionTemplate> temp = NanNew<FunctionTemplate>(New);
116114
temp->InstanceTemplate()->SetInternalFieldCount(1);
117115
temp->SetClassName(NanNew<v8::String>("Oracledb"));
118116

src/njs/src/njsOracle.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ using namespace v8;
7777
(NJS_NODE_ORACLEDB_MINOR * 100) + \
7878
(NJS_NODE_ORACLEDB_PATCH) )
7979

80+
#define NJS_PREFETCH_ROWS_NOT_SET -1 // by default prefetch is not set, so -1
8081

8182
class Oracledb: public ObjectWrap
8283
{
@@ -94,7 +95,7 @@ class Oracledb: public ObjectWrap
9495
unsigned int getPoolMax () const { return poolMax_; }
9596
unsigned int getPoolIncrement () const { return poolIncrement_; }
9697
unsigned int getPoolTimeout () const { return poolTimeout_; }
97-
unsigned int getPrefetchRows () const { return prefetchRows_; }
98+
signed int getPrefetchRows () const { return prefetchRows_; }
9899
const std::string& getConnectionClass () const { return connClass_; }
99100

100101

@@ -152,7 +153,7 @@ class Oracledb: public ObjectWrap
152153
unsigned int maxRows_;
153154

154155
unsigned int stmtCacheSize_;
155-
int prefetchRows_;
156+
signed int prefetchRows_;
156157

157158
unsigned int poolMin_;
158159
unsigned int poolMax_;

0 commit comments

Comments
 (0)