Skip to content

Commit 09c6849

Browse files
committed
Test getting registration ID for subscriptions
1 parent dcb7bd6 commit 09c6849

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

test/list.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4405,6 +4405,7 @@ oracledb.OUT_FORMAT_OBJECT and resultSet = true
44054405
185.3 Specify the notification only for INSERT operation
44064406
185.4 Negative - provide invalid SQL in CQN option
44074407
185.5 examples/cqn2.js
4408+
185.6 getting registration ID "regId" for subscriptions
44084409

44094410
186. instanceof2.js
44104411
186.1 instanceof checks for SODA classes

test/runCQN.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,4 +317,56 @@ describe('185. runCQN.js', function() {
317317
should.not.exist(err);
318318
}
319319
}); // 185.5
320+
321+
it('185.6 getting registration ID "regId" for subscriptions', async () => {
322+
try {
323+
const TABLE = 'nodb_tab_cqn_6';
324+
let sql =
325+
`CREATE TABLE ${TABLE} (
326+
k NUMBER
327+
)`;
328+
let plsql = testsUtil.sqlCreateTable(TABLE, sql);
329+
await conn.execute(plsql);
330+
331+
const myCallback = async function(message) {
332+
// console.log(message);
333+
should.strictEqual(message.registered, true);
334+
};
335+
336+
const options = {
337+
callback : myCallback,
338+
sql: `SELECT * FROM ${TABLE} WHERE k > :bv`,
339+
binds: { bv : 100 },
340+
timeout : 20,
341+
qos : oracledb.SUBSCR_QOS_QUERY | oracledb.SUBSCR_QOS_ROWIDS
342+
};
343+
344+
let sleepPLSQL = `BEGIN DBMS_SESSION.SLEEP(2); END;`;
345+
await conn.execute(plsql);
346+
await conn.commit();
347+
348+
const result = await conn.subscribe('sub6', options);
349+
(result.regId).should.be.a.Number();
350+
351+
const tableName = dbconfig.user.toUpperCase() + '.' + TABLE.toUpperCase();
352+
sql = `SELECT regid FROM USER_CHANGE_NOTIFICATION_REGS
353+
WHERE table_name = '${tableName}'`;
354+
const res = await conn.execute(sql, [], { outFormat: oracledb.OUT_FORMAT_OBJECT });
355+
should.strictEqual(result.regId, res.rows[0].REGID);
356+
357+
sql = `INSERT INTO ${TABLE} VALUES (101)`;
358+
await conn.execute(sql);
359+
360+
await conn.execute(sleepPLSQL);
361+
await conn.commit();
362+
363+
await conn.unsubscribe('sub6');
364+
365+
sql = `DROP TABLE ${TABLE} PURGE`;
366+
await conn.execute(sql);
367+
} catch (err) {
368+
should.not.exist(err);
369+
}
370+
}); // 185.6
371+
320372
});

0 commit comments

Comments
 (0)