Skip to content

Commit 8e4806e

Browse files
committed
Raise error when SQL missing from subscription options for CQN
1 parent 6dd5276 commit 8e4806e

File tree

5 files changed

+22
-14
lines changed

5 files changed

+22
-14
lines changed

src/njsCommon.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,6 @@ class njsBaton {
329329
uint32_t subscrGroupingClass;
330330
uint32_t subscrGroupingValue;
331331
uint32_t subscrGroupingType;
332-
dpiSubscrNamespace subscrNamespace;
333332
njsSubscription *subscription;
334333
njsCommon *callingObj;
335334
Nan::Persistent<Object> jsCallingObj;
@@ -356,9 +355,7 @@ class njsBaton {
356355
rowCounts(NULL), timeout(0), qos(0), operations(0),
357356
numBatchErrorInfos(0), batchErrorInfos(NULL), dpiError(false),
358357
portNumber(0), subscrGroupingClass(0), subscrGroupingValue(0),
359-
subscrGroupingType(0),
360-
subscrNamespace(DPI_SUBSCR_NAMESPACE_DBCHANGE),
361-
subscription(NULL) {
358+
subscrGroupingType(0), subscription(NULL) {
362359
this->jsCallback.Reset(callback);
363360
this->jsCallingObj.Reset(callingObj);
364361
this->callingObj = Nan::ObjectWrap::Unwrap<njsCommon>(callingObj);

src/njsConnection.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,7 +1406,7 @@ bool njsConnection::ProcessSubscriptionOptions(Local<Object> options,
14061406
if (!baton->GetUnsignedIntFromJSON(options, "namespace", 1,
14071407
&temp))
14081408
return false;
1409-
baton->subscrNamespace = (dpiSubscrNamespace) temp;
1409+
baton->subscription->SetNamespace((dpiSubscrNamespace) temp);
14101410
if (!baton->GetStringFromJSON(options, "ipAddress", 1,
14111411
baton->ipAddress))
14121412
return false;
@@ -1439,14 +1439,20 @@ bool njsConnection::ProcessSubscriptionOptions(Local<Object> options,
14391439
}
14401440

14411441
// get options that are used for registering queries
1442-
if (!baton->GetStringFromJSON(options, "sql", 1, baton->sql))
1443-
return false;
1444-
Local<Value> binds;
1445-
Local<String> key = Nan::New("binds").ToLocalChecked();
1446-
if (!Nan::Get(options, key).ToLocal(&binds))
1447-
return false;
1448-
if (!ProcessExecuteBinds(binds.As<Object>(), baton))
1449-
return false;
1442+
if (baton->subscription->GetNamespace() == DPI_SUBSCR_NAMESPACE_DBCHANGE) {
1443+
if (!baton->GetStringFromJSON(options, "sql", 1, baton->sql))
1444+
return false;
1445+
if (baton->sql.empty()) {
1446+
baton->error = njsMessages::Get(errMissingSubscrSql);
1447+
return false;
1448+
}
1449+
Local<Value> binds;
1450+
Local<String> key = Nan::New("binds").ToLocalChecked();
1451+
if (!Nan::Get(options, key).ToLocal(&binds))
1452+
return false;
1453+
if (!ProcessExecuteBinds(binds.As<Object>(), baton))
1454+
return false;
1455+
}
14501456

14511457
return true;
14521458
}
@@ -2514,7 +2520,7 @@ void njsConnection::Async_Subscribe(njsBaton *baton)
25142520
baton->GetDPIError();
25152521
return;
25162522
}
2517-
params.subscrNamespace = baton->subscrNamespace;
2523+
params.subscrNamespace = baton->subscription->GetNamespace();
25182524
params.name = baton->name.c_str();
25192525
params.nameLength = baton->name.length();
25202526
params.protocol = DPI_SUBSCR_PROTO_CALLBACK;

src/njsMessages.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ static const char *errMsg[] = {
9191
"NJS-060: type must be specified for bind \"%s\"", // errMissingTypeByName
9292
"NJS-061: invalid subscription", // errInvalidSubscription
9393
"NJS-062: subscription notification callback missing", // errMissingSubscrCallback
94+
"NJS-063: subscription notification SQL missing", // errMissingSubscrSql
9495
};
9596

9697

src/njsMessages.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ typedef enum {
9494
errMissingTypeByName,
9595
errInvalidSubscription,
9696
errMissingSubscrCallback,
97+
errMissingSubscrSql,
9798

9899
// New ones should be added here
99100

src/njsSubscription.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ class njsSubscription: public njsCommon {
6767
bool IsValid() const { return true; };
6868
njsErrorType GetInvalidErrorType() const { return errInvalidSubscription; }
6969
static Local<Object> Create();
70+
dpiSubscrNamespace GetNamespace() const { return subscrNamespace; }
71+
void SetNamespace(dpiSubscrNamespace ns) { subscrNamespace = ns; }
7072
void SetCallback(Local<Function> callback) { jsCallback.Reset(callback); }
7173
void SetDPISubscrHandle(njsBaton *baton)
7274
{ baton->SetDPISubscrHandle(dpiSubscrHandle); }
@@ -99,6 +101,7 @@ class njsSubscription: public njsCommon {
99101
uv_barrier_t barrier;
100102
dpiSubscrMessage *message;
101103
Nan::Persistent<Function> jsCallback;
104+
dpiSubscrNamespace subscrNamespace;
102105
std::string name;
103106

104107
static Nan::Persistent<FunctionTemplate> subscriptionTemplate_s;

0 commit comments

Comments
 (0)