@@ -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 ++ )
0 commit comments