@@ -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