49
49
*****************************************************************************/
50
50
51
51
#include " njsConnection.h"
52
+ #include " njsResultSet.h"
52
53
#include < stdlib.h>
53
54
#include < iostream>
54
55
using namespace std ;
@@ -340,10 +341,12 @@ NAN_METHOD(Connection::Execute)
340
341
NJSString (executeBaton->sql , sql);
341
342
342
343
executeBaton->maxRows = connection->oracledb_ ->getMaxRows ();
344
+ executeBaton->prefetchRows = connection->oracledb_ ->getPrefetchRows ();
343
345
executeBaton->outFormat = connection->oracledb_ ->getOutFormat ();
344
346
executeBaton->autoCommit = connection->oracledb_ ->getAutoCommit ();
345
347
executeBaton->dpienv = connection->oracledb_ ->getDpiEnv ();
346
348
executeBaton->dpiconn = connection->dpiconn_ ;
349
+ executeBaton->njsconn = connection;
347
350
348
351
if (args.Length () > 2 )
349
352
{
@@ -411,8 +414,12 @@ void Connection::ProcessOptions (_NAN_METHOD_ARGS, unsigned int index,
411
414
options = args[index]->ToObject ();
412
415
NJS_GET_UINT_FROM_JSON ( executeBaton->maxRows , executeBaton->error ,
413
416
options, " maxRows" , 2 , exitProcessOptions );
417
+ NJS_GET_UINT_FROM_JSON ( executeBaton->prefetchRows , executeBaton->error ,
418
+ options, " prefetchRows" , 2 , exitProcessOptions );
414
419
NJS_GET_UINT_FROM_JSON ( executeBaton->outFormat , executeBaton->error ,
415
420
options, " outFormat" , 2 , exitProcessOptions );
421
+ NJS_GET_BOOL_FROM_JSON ( executeBaton->getRS , executeBaton->error ,
422
+ options, " resultSet" , 2 , exitProcessOptions );
416
423
NJS_GET_BOOL_FROM_JSON ( executeBaton->autoCommit , executeBaton->error ,
417
424
options, " autoCommit" , 2 , exitProcessOptions );
418
425
}
@@ -731,10 +738,22 @@ void Connection::Async_Execute (uv_work_t *req)
731
738
if (executeBaton->st == DpiStmtSelect)
732
739
{
733
740
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 );
735
748
}
736
749
else
737
750
{
751
+ if ( executeBaton->getRS )
752
+ {
753
+ executeBaton->error = NJSMessages::getErrorMsg (
754
+ errInvalidNonQueryExecution );
755
+ goto exitAsyncExecute;
756
+ }
738
757
executeBaton->dpistmt ->execute (1 , executeBaton->autoCommit );
739
758
executeBaton->rowsAffected = executeBaton->dpistmt ->rowsAffected ();
740
759
@@ -797,7 +816,7 @@ void Connection::Async_Execute (uv_work_t *req)
797
816
// In Case of DML Returning, if the buffer is small, and if the callback
798
817
// is called multiple times, an ORA error 24343 was reported. Converting
799
818
// that error to errInsufficientBufferForBinds.
800
- if ( !executeBaton->stmtIsReturning &&
819
+ if ( !executeBaton->stmtIsReturning &&
801
820
(e.errnum () != 24343 ) )
802
821
{
803
822
executeBaton->error = std::string (e.what ());
@@ -826,6 +845,9 @@ void Connection::PrepareAndBind (eBaton* executeBaton)
826
845
executeBaton->st = executeBaton->dpistmt ->stmtType ();
827
846
executeBaton->stmtIsReturning = executeBaton->dpistmt ->isReturning ();
828
847
848
+ if (executeBaton->getRS && executeBaton->prefetchRows > -1 )
849
+ executeBaton->dpistmt ->prefetchRows (executeBaton->prefetchRows );
850
+
829
851
if (!executeBaton->binds .empty ())
830
852
{
831
853
if (!executeBaton->binds [0 ]->key .empty ())
@@ -930,6 +952,24 @@ void Connection::PrepareAndBind (eBaton* executeBaton)
930
952
}
931
953
}
932
954
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
+
933
973
/* ****************************************************************************/
934
974
/*
935
975
DESCRIPTION
@@ -939,19 +979,13 @@ void Connection::PrepareAndBind (eBaton* executeBaton)
939
979
PARAMETERS:
940
980
eBaton struct
941
981
*/
942
- void Connection::GetDefines (eBaton* executeBaton)
982
+ void Connection::GetDefines ( eBaton* executeBaton, const dpi::MetaData* meta,
983
+ unsigned int numCols )
943
984
{
944
- unsigned int numCols = executeBaton->dpistmt ->numCols ();
945
985
Define *defines = new Define[numCols];
946
- const dpi::MetaData* meta = executeBaton->dpistmt ->getMetaData ();
947
- executeBaton->columnNames = new std::string[numCols];
948
986
949
987
for (unsigned int i = 0 ; i < numCols; i++)
950
988
{
951
-
952
- executeBaton->columnNames [i] = std::string ((const char *)meta[i].colName ,
953
- meta[i].colNameLen );
954
-
955
989
switch (meta[i].dbType )
956
990
{
957
991
case dpi::DpiNumber :
@@ -993,8 +1027,22 @@ void Connection::GetDefines (eBaton* executeBaton)
993
1027
executeBaton->defines = defines;
994
1028
executeBaton->numCols = numCols;
995
1029
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
996
1039
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
+ {
998
1046
for (unsigned int col = 0 ; col < numCols; col ++ )
999
1047
{
1000
1048
if ( defines[col].dttmarr )
@@ -1003,15 +1051,18 @@ void Connection::GetDefines (eBaton* executeBaton)
1003
1051
1004
1052
defines[col].buf =
1005
1053
dblArr = (long double *)malloc ( sizeof ( long double ) *
1006
- executeBaton-> rowsFetched );
1054
+ rowsFetched );
1007
1055
1008
- for ( int row = 0 ; row < (int ) executeBaton-> rowsFetched ; row ++ )
1056
+ for ( int row = 0 ; row < (int ) rowsFetched; row ++ )
1009
1057
{
1010
1058
dblArr[row] = defines[col].dttmarr ->getDateTime (row) * NJS_DAY2MS;
1011
1059
}
1012
1060
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
+ }
1015
1066
}
1016
1067
}
1017
1068
@@ -1055,7 +1106,23 @@ void Connection::Async_AfterExecute(uv_work_t *req)
1055
1106
argv[1 ] = NanUndefined ();
1056
1107
goto exitAsyncAfterExecute;
1057
1108
}
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
+ }
1059
1126
result->Set (NanNew<v8::String>(" outBinds" ),NanUndefined ());
1060
1127
result->Set (NanNew<v8::String>(" rowsAffected" ), NanUndefined ());
1061
1128
result->Set (NanNew<v8::String>(" metaData" ), Connection::GetMetaData (
0 commit comments