Skip to content

Commit d433c3d

Browse files
committed
Revert throw vs callback error change
1 parent 727d447 commit d433c3d

File tree

7 files changed

+74
-36
lines changed

7 files changed

+74
-36
lines changed

lib/oracledb.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,18 @@ function extend(oracledb) {
296296
value: 232,
297297
enumerable: true
298298
},
299+
DB_TYPE_NVARCHAR: {
300+
value : 1001,
301+
enumerable : true
302+
},
303+
DB_TYPE_NCHAR: {
304+
value : 1096,
305+
enumerable : true
306+
},
307+
DB_TYPE_NCLOB: {
308+
value : 1112,
309+
enumerable : true
310+
},
299311
STRING: {
300312
value: 2001,
301313
enumerable: true

src/njs/src/njsCommon.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,13 @@ njsDBType njsVariable::DBType()
124124
{
125125
switch (dbTypeNum) {
126126
case DPI_ORACLE_TYPE_VARCHAR:
127-
case DPI_ORACLE_TYPE_NVARCHAR:
128127
return NJS_DB_TYPE_VARCHAR;
128+
case DPI_ORACLE_TYPE_NVARCHAR:
129+
return NJS_DB_TYPE_NVARCHAR;
129130
case DPI_ORACLE_TYPE_CHAR:
130-
case DPI_ORACLE_TYPE_NCHAR:
131131
return NJS_DB_TYPE_CHAR;
132+
case DPI_ORACLE_TYPE_NCHAR:
133+
return NJS_DB_TYPE_NCHAR;
132134
case DPI_ORACLE_TYPE_ROWID:
133135
return NJS_DB_TYPE_ROWID;
134136
case DPI_ORACLE_TYPE_RAW:
@@ -149,8 +151,9 @@ njsDBType njsVariable::DBType()
149151
case DPI_ORACLE_TYPE_TIMESTAMP_LTZ:
150152
return NJS_DB_TYPE_TIMESTAMP_LTZ;
151153
case DPI_ORACLE_TYPE_CLOB:
152-
case DPI_ORACLE_TYPE_NCLOB:
153154
return NJS_DB_TYPE_CLOB;
155+
case DPI_ORACLE_TYPE_NCLOB:
156+
return NJS_DB_TYPE_NCLOB;
154157
case DPI_ORACLE_TYPE_BLOB:
155158
return NJS_DB_TYPE_BLOB;
156159
case DPI_ORACLE_TYPE_LONG_VARCHAR:
@@ -516,7 +519,7 @@ void njsBaton::QueueWork(const char *methodName,
516519

517520

518521
//-----------------------------------------------------------------------------
519-
// njsCommon::CreatnjsBaton()
522+
// njsCommon::CreateBaton()
520523
// Creates a baton for use in asynchronous methods. In each of these cases
521524
// the last argument passed in from JS is expected to be a JS callback. NULL is
522525
// returned and an exception raised for JS if this is not the case.
@@ -525,14 +528,20 @@ njsBaton *njsCommon::CreateBaton(Nan::NAN_METHOD_ARGS_TYPE args)
525528
{
526529
Nan::HandleScope scope;
527530
Local<Function> callback;
531+
njsBaton *baton;
528532

529533
if (!args.Length() || !args[(args.Length() - 1)]->IsFunction()) {
530534
string errMsg = njsMessages::Get(errMissingCallback);
531535
Nan::ThrowError(errMsg.c_str());
532536
return NULL;
533537
}
534538
callback = Local<Function>::Cast(args[args.Length() - 1]);
535-
return new njsBaton(callback, args.Holder());
539+
baton = new njsBaton(callback, args.Holder());
540+
if (!IsValid()) {
541+
njsErrorType errNum = GetInvalidErrorType();
542+
baton->error = njsMessages::Get(errNum);
543+
}
544+
return baton;
536545
}
537546

538547

@@ -735,8 +744,11 @@ njsCommon *njsCommon::ValidateArgs(Nan::NAN_METHOD_ARGS_TYPE args,
735744
string errMsg;
736745

737746
obj = Nan::ObjectWrap::Unwrap<njsCommon>(args.Holder());
738-
if (!Validate(obj))
747+
if (!obj) {
748+
errMsg = njsMessages::Get(errInvalidJSObject);
749+
Nan::ThrowError(errMsg.c_str());
739750
return NULL;
751+
}
740752
if (args.Length() < minArgs || args.Length() > maxArgs) {
741753
errMsg = njsMessages::Get(errInvalidNumberOfParameters);
742754
Nan::ThrowError(errMsg.c_str());

src/njs/src/njsCommon.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,12 @@ typedef enum {
135135
NJS_DB_TYPE_BLOB = 113,
136136
NJS_DB_TYPE_TIMESTAMP = 187,
137137
NJS_DB_TYPE_TIMESTAMP_TZ = 188,
138-
NJS_DB_TYPE_TIMESTAMP_LTZ = 232
138+
NJS_DB_TYPE_TIMESTAMP_LTZ = 232,
139+
140+
/* Pseudo types */
141+
NJS_DB_TYPE_NCHAR = 1096,
142+
NJS_DB_TYPE_NVARCHAR = 1001,
143+
NJS_DB_TYPE_NCLOB = 1112,
139144
} njsDBType;
140145

141146

src/njs/src/njsConnection.cpp

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,20 +1385,22 @@ NAN_METHOD(njsConnection::Execute)
13851385
baton = connection->CreateBaton(info);
13861386
if (!baton)
13871387
return;
1388-
baton->sql = sql;
1389-
baton->SetDPIConnHandle(connection->dpiConnHandle);
1390-
baton->jsOracledb.Reset(connection->jsOracledb);
1391-
oracledb = baton->GetOracledb();
1392-
baton->maxRows = oracledb->getMaxRows();
1393-
baton->prefetchRows = oracledb->getPrefetchRows();
1394-
oracledb->SetFetchAsStringTypesOnBaton(baton);
1395-
oracledb->SetFetchAsBufferTypesOnBaton(baton);
1396-
baton->outFormat = oracledb->getOutFormat();
1397-
baton->autoCommit = oracledb->getAutoCommit();
1398-
baton->extendedMetaData = oracledb->getExtendedMetaData();
1399-
baton->getRS = false;
1400-
bool ok = true;
1401-
if (info.Length() > 2)
1388+
bool ok = baton->error.empty();
1389+
if (ok) {
1390+
baton->sql = sql;
1391+
baton->SetDPIConnHandle(connection->dpiConnHandle);
1392+
baton->jsOracledb.Reset(connection->jsOracledb);
1393+
oracledb = baton->GetOracledb();
1394+
baton->maxRows = oracledb->getMaxRows();
1395+
baton->prefetchRows = oracledb->getPrefetchRows();
1396+
oracledb->SetFetchAsStringTypesOnBaton(baton);
1397+
oracledb->SetFetchAsBufferTypesOnBaton(baton);
1398+
baton->outFormat = oracledb->getOutFormat();
1399+
baton->autoCommit = oracledb->getAutoCommit();
1400+
baton->extendedMetaData = oracledb->getExtendedMetaData();
1401+
baton->getRS = false;
1402+
}
1403+
if (ok && info.Length() > 2)
14021404
ok = ProcessBinds(info, 1, baton);
14031405
if (ok && info.Length() > 3)
14041406
ProcessOptions(info, 2, baton);
@@ -1608,7 +1610,8 @@ NAN_METHOD(njsConnection::Commit)
16081610
baton = connection->CreateBaton(info);
16091611
if (!baton)
16101612
return;
1611-
baton->SetDPIConnHandle(connection->dpiConnHandle);
1613+
if (baton->error.empty())
1614+
baton->SetDPIConnHandle(connection->dpiConnHandle);
16121615
baton->QueueWork("Commit", Async_Commit, NULL, 1);
16131616
}
16141617

@@ -1642,7 +1645,8 @@ NAN_METHOD(njsConnection::Rollback)
16421645
baton = connection->CreateBaton(info);
16431646
if (!baton)
16441647
return;
1645-
baton->SetDPIConnHandle(connection->dpiConnHandle);
1648+
if (baton->error.empty())
1649+
baton->SetDPIConnHandle(connection->dpiConnHandle);
16461650
baton->QueueWork("Rollback", Async_Rollback, NULL, 1);
16471651
}
16481652

@@ -1676,7 +1680,8 @@ NAN_METHOD(njsConnection::Break)
16761680
baton = connection->CreateBaton(info);
16771681
if (!baton)
16781682
return;
1679-
baton->SetDPIConnHandle(connection->dpiConnHandle);
1683+
if (baton->error.empty())
1684+
baton->SetDPIConnHandle(connection->dpiConnHandle);
16801685
baton->QueueWork("Break", Async_Break, NULL, 1);
16811686
}
16821687

@@ -1718,10 +1723,12 @@ NAN_METHOD(njsConnection::CreateLob)
17181723
Nan::ThrowError(errMsg.c_str());
17191724
return;
17201725
}
1721-
baton->jsOracledb.Reset(connection->jsOracledb);
1722-
baton->SetDPIConnHandle(connection->dpiConnHandle);
1723-
baton->protoILob = new njsProtoILob();
1724-
baton->protoILob->dataType = (njsDataType) lobType;
1726+
if (baton->error.empty()) {
1727+
baton->jsOracledb.Reset(connection->jsOracledb);
1728+
baton->SetDPIConnHandle(connection->dpiConnHandle);
1729+
baton->protoILob = new njsProtoILob();
1730+
baton->protoILob->dataType = (njsDataType) lobType;
1731+
}
17251732
baton->QueueWork("CreateLob", Async_CreateLob, Async_AfterCreateLob, 2);
17261733
}
17271734

src/njs/src/njsIntLob.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ NAN_METHOD(njsILob::Read)
419419
return;
420420
if (lob->activeBaton)
421421
baton->error = njsMessages::Get(errBusyLob);
422-
else {
422+
else if (baton->error.empty()) {
423423
lob->activeBaton = baton;
424424
if (lob->dataType == NJS_DATATYPE_BLOB)
425425
baton->bufferSize = lob->pieceSize;
@@ -544,7 +544,7 @@ NAN_METHOD(njsILob::Write)
544544
return;
545545
if (lob->activeBaton)
546546
baton->error = njsMessages::Get(errBusyLob);
547-
else {
547+
else if (baton->error.empty()) {
548548
baton->jsBuffer.Reset(jsBuffer);
549549
baton->bufferPtr = Buffer::Data(jsBuffer);
550550
baton->bufferSize = Buffer::Length(jsBuffer);

src/njs/src/njsPool.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -361,11 +361,13 @@ NAN_METHOD(njsPool::GetConnection)
361361
baton = pool->CreateBaton(info);
362362
if (!baton)
363363
return;
364-
baton->jsOracledb.Reset(pool->jsOracledb);
365-
njsOracledb *oracledb = baton->GetOracledb();
366-
baton->connClass = oracledb->getConnectionClass();
367-
baton->lobPrefetchSize = pool->lobPrefetchSize;
368-
baton->SetDPIPoolHandle(pool->dpiPoolHandle);
364+
if (baton->error.empty()) {
365+
baton->jsOracledb.Reset(pool->jsOracledb);
366+
njsOracledb *oracledb = baton->GetOracledb();
367+
baton->connClass = oracledb->getConnectionClass();
368+
baton->lobPrefetchSize = pool->lobPrefetchSize;
369+
baton->SetDPIPoolHandle(pool->dpiPoolHandle);
370+
}
369371
baton->QueueWork("GetConnection", Async_GetConnection,
370372
Async_AfterGetConnection, 2);
371373
}

src/njs/src/njsResultSet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ void njsResultSet::GetRowsCommon(njsBaton *baton)
325325
{
326326
if (activeBaton)
327327
baton->error = njsMessages::Get(errBusyResultSet);
328-
else {
328+
else if (baton->error.empty()) {
329329
activeBaton = baton;
330330
baton->SetDPIStmtHandle(dpiStmtHandle);
331331
baton->SetDPIConnHandle(dpiConnHandle);

0 commit comments

Comments
 (0)