4949 *****************************************************************************/
5050
5151#include " njsConnection.h"
52+ #include " njsResultSet.h"
5253#include < stdlib.h>
5354#include < iostream>
5455using namespace std ;
@@ -340,10 +341,12 @@ NAN_METHOD(Connection::Execute)
340341 NJSString (executeBaton->sql , sql);
341342
342343 executeBaton->maxRows = connection->oracledb_ ->getMaxRows ();
344+ executeBaton->prefetchRows = connection->oracledb_ ->getPrefetchRows ();
343345 executeBaton->outFormat = connection->oracledb_ ->getOutFormat ();
344346 executeBaton->autoCommit = connection->oracledb_ ->getAutoCommit ();
345347 executeBaton->dpienv = connection->oracledb_ ->getDpiEnv ();
346348 executeBaton->dpiconn = connection->dpiconn_ ;
349+ executeBaton->njsconn = connection;
347350
348351 if (args.Length () > 2 )
349352 {
@@ -411,8 +414,12 @@ void Connection::ProcessOptions (_NAN_METHOD_ARGS, unsigned int index,
411414 options = args[index]->ToObject ();
412415 NJS_GET_UINT_FROM_JSON ( executeBaton->maxRows , executeBaton->error ,
413416 options, " maxRows" , 2 , exitProcessOptions );
417+ NJS_GET_UINT_FROM_JSON ( executeBaton->prefetchRows , executeBaton->error ,
418+ options, " prefetchRows" , 2 , exitProcessOptions );
414419 NJS_GET_UINT_FROM_JSON ( executeBaton->outFormat , executeBaton->error ,
415420 options, " outFormat" , 2 , exitProcessOptions );
421+ NJS_GET_BOOL_FROM_JSON ( executeBaton->getRS , executeBaton->error ,
422+ options, " resultSet" , 2 , exitProcessOptions );
416423 NJS_GET_BOOL_FROM_JSON ( executeBaton->autoCommit , executeBaton->error ,
417424 options, " autoCommit" , 2 , exitProcessOptions );
418425 }
@@ -731,10 +738,22 @@ void Connection::Async_Execute (uv_work_t *req)
731738 if (executeBaton->st == DpiStmtSelect)
732739 {
733740 executeBaton->dpistmt ->execute (0 , executeBaton->autoCommit );
734- Connection::GetDefines (executeBaton);
741+ const dpi::MetaData* meta = executeBaton->dpistmt ->getMetaData ();
742+ executeBaton->numCols = executeBaton->dpistmt ->numCols ();
743+ executeBaton->columnNames = new std::string[executeBaton->numCols ];
744+ Connection::metaData ( executeBaton->columnNames , meta,
745+ executeBaton->numCols );
746+ if ( executeBaton->getRS ) goto exitAsyncExecute;
747+ Connection::GetDefines (executeBaton, meta, executeBaton->numCols );
735748 }
736749 else
737750 {
751+ if ( executeBaton->getRS )
752+ {
753+ executeBaton->error = NJSMessages::getErrorMsg (
754+ errInvalidNonQueryExecution );
755+ goto exitAsyncExecute;
756+ }
738757 executeBaton->dpistmt ->execute (1 , executeBaton->autoCommit );
739758 executeBaton->rowsAffected = executeBaton->dpistmt ->rowsAffected ();
740759
@@ -797,7 +816,7 @@ void Connection::Async_Execute (uv_work_t *req)
797816 // In Case of DML Returning, if the buffer is small, and if the callback
798817 // is called multiple times, an ORA error 24343 was reported. Converting
799818 // that error to errInsufficientBufferForBinds.
800- if ( !executeBaton->stmtIsReturning &&
819+ if ( !executeBaton->stmtIsReturning &&
801820 (e.errnum () != 24343 ) )
802821 {
803822 executeBaton->error = std::string (e.what ());
@@ -826,6 +845,9 @@ void Connection::PrepareAndBind (eBaton* executeBaton)
826845 executeBaton->st = executeBaton->dpistmt ->stmtType ();
827846 executeBaton->stmtIsReturning = executeBaton->dpistmt ->isReturning ();
828847
848+ if (executeBaton->getRS && executeBaton->prefetchRows > -1 )
849+ executeBaton->dpistmt ->prefetchRows (executeBaton->prefetchRows );
850+
829851 if (!executeBaton->binds .empty ())
830852 {
831853 if (!executeBaton->binds [0 ]->key .empty ())
@@ -930,6 +952,24 @@ void Connection::PrepareAndBind (eBaton* executeBaton)
930952 }
931953}
932954
955+ /* ****************************************************************************/
956+ /*
957+ DESCRIPTION
958+ get meta data into baton
959+
960+ PARAMETERS:
961+ string arrat, metaData, numCols
962+ */
963+ void Connection::metaData ( std::string* names, const dpi::MetaData* meta,
964+ unsigned int numCols )
965+ {
966+ for (unsigned int i = 0 ; i < numCols; i++)
967+ {
968+ names[i] = std::string ( (const char *)meta[i].colName ,
969+ meta[i].colNameLen );
970+ }
971+ }
972+
933973/* ****************************************************************************/
934974/*
935975 DESCRIPTION
@@ -939,19 +979,13 @@ void Connection::PrepareAndBind (eBaton* executeBaton)
939979 PARAMETERS:
940980 eBaton struct
941981 */
942- void Connection::GetDefines (eBaton* executeBaton)
982+ void Connection::GetDefines ( eBaton* executeBaton, const dpi::MetaData* meta,
983+ unsigned int numCols )
943984{
944- unsigned int numCols = executeBaton->dpistmt ->numCols ();
945985 Define *defines = new Define[numCols];
946- const dpi::MetaData* meta = executeBaton->dpistmt ->getMetaData ();
947- executeBaton->columnNames = new std::string[numCols];
948986
949987 for (unsigned int i = 0 ; i < numCols; i++)
950988 {
951-
952- executeBaton->columnNames [i] = std::string ((const char *)meta[i].colName ,
953- meta[i].colNameLen );
954-
955989 switch (meta[i].dbType )
956990 {
957991 case dpi::DpiNumber :
@@ -993,8 +1027,22 @@ void Connection::GetDefines (eBaton* executeBaton)
9931027 executeBaton->defines = defines;
9941028 executeBaton->numCols = numCols;
9951029 executeBaton->rowsFetched = executeBaton->dpistmt ->rowsFetched ();
1030+ Connection::descr2Dbl (executeBaton->defines , numCols,
1031+ executeBaton->rowsFetched ,
1032+ executeBaton->getRS );
1033+ }
1034+
1035+ /* ****************************************************************************/
1036+ /*
1037+ DESCRIPTION
1038+ Special processing for datetime, as it is obtained as descriptors
9961039
997- /* Special processing for datetime, as it is obtained as descriptors */
1040+ PARAMETERS:
1041+ Define struct, numCols
1042+ */
1043+ void Connection::descr2Dbl ( Define* defines, unsigned int numCols,
1044+ unsigned int rowsFetched, bool getRS )
1045+ {
9981046 for (unsigned int col = 0 ; col < numCols; col ++ )
9991047 {
10001048 if ( defines[col].dttmarr )
@@ -1003,15 +1051,18 @@ void Connection::GetDefines (eBaton* executeBaton)
10031051
10041052 defines[col].buf =
10051053 dblArr = (long double *)malloc ( sizeof ( long double ) *
1006- executeBaton-> rowsFetched );
1054+ rowsFetched );
10071055
1008- for ( int row = 0 ; row < (int ) executeBaton-> rowsFetched ; row ++ )
1056+ for ( int row = 0 ; row < (int ) rowsFetched; row ++ )
10091057 {
10101058 dblArr[row] = defines[col].dttmarr ->getDateTime (row) * NJS_DAY2MS;
10111059 }
10121060 defines[col].buf = (void *) dblArr;
1013- defines[col].dttmarr ->release ();
1014- defines[col].extbuf = NULL ;
1061+ if ( !getRS )
1062+ {
1063+ defines[col].dttmarr ->release ();
1064+ defines[col].extbuf = NULL ;
1065+ }
10151066 }
10161067 }
10171068
@@ -1055,7 +1106,23 @@ void Connection::Async_AfterExecute(uv_work_t *req)
10551106 argv[1 ] = NanUndefined ();
10561107 goto exitAsyncAfterExecute;
10571108 }
1058- result->Set (NanNew<v8::String>(" rows" ), rowArray);// , v8::ReadOnly);
1109+ if ( executeBaton->getRS )
1110+ {
1111+ result->Set (NanNew<v8::String>(" rows" ), NanUndefined ());
1112+ Handle<Object> resultSet = NanNew (ResultSet::resultSetTemplate_s)->
1113+ GetFunction () ->NewInstance ();
1114+ (ObjectWrap::Unwrap<ResultSet> (resultSet))->
1115+ setResultSet ( executeBaton->dpistmt ,
1116+ executeBaton->dpienv ,
1117+ executeBaton->njsconn ,
1118+ executeBaton->outFormat );
1119+ result->Set (NanNew<v8::String>(" resultSet" ), resultSet );
1120+ }
1121+ else
1122+ {
1123+ result->Set (NanNew<v8::String>(" rows" ), rowArray);
1124+ result->Set (NanNew<v8::String>(" resultSet" ), NanUndefined ());
1125+ }
10591126 result->Set (NanNew<v8::String>(" outBinds" ),NanUndefined ());
10601127 result->Set (NanNew<v8::String>(" rowsAffected" ), NanUndefined ());
10611128 result->Set (NanNew<v8::String>(" metaData" ), Connection::GetMetaData (
0 commit comments