@@ -51,6 +51,7 @@ Error.stackTraceLimit = 50;
51
51
const http = require ( 'http' ) ;
52
52
const oracledb = require ( 'oracledb' ) ;
53
53
const dbConfig = require ( './dbconfig.js' ) ;
54
+
54
55
const httpPort = 7000 ;
55
56
56
57
// This example runs in both node-oracledb Thin and Thick modes.
@@ -76,19 +77,22 @@ if (process.env.NODE_ORACLEDB_DRIVER_MODE === 'thick') {
76
77
77
78
// initSession() will be invoked internally when each brand new pooled
78
79
// connection is first used. Its callback function 'callbackFn' should be
79
- // invoked only when all desired session state has been set.
80
- // In this example, the requestedTag and actualTag parameters are
81
- // ignored. They would be valid if connection tagging was being used.
82
- // If you have multiple SQL statements to execute, put them in a
83
- // single, anonymous PL/SQL block for efficiency.
80
+ // invoked only when all desired session state has been set. In this example,
81
+ // the requestedTag parameter is ignored. They would be valid if connection
82
+ // tagging was being used. If you have multiple SQL statements to execute, put
83
+ // them in a single, anonymous PL/SQL block for efficiency.
84
84
function initSession ( connection , requestedTag , callbackFn ) {
85
+
85
86
// Your session initialization code would be here. This example just queries
86
- // the session id to show that the callback is invoked once per session.
87
+ // the session id and serial number to show that the callback is invoked once
88
+ // per new session.
87
89
connection . execute (
88
- `SELECT SYS_CONTEXT('USERENV','SID') FROM DUAL` ,
90
+ `SELECT UNIQUE sid||'-'||serial#
91
+ FROM v$session_connect_info
92
+ WHERE sid = SYS_CONTEXT('USERENV', 'SID')` ,
89
93
function ( err , result ) {
90
- const sid = result . rows [ 0 ] [ 0 ] ; // session id
91
- console . log ( `initSession invoked for session ${ sid } ` ) ;
94
+ const sidSer = result . rows [ 0 ] [ 0 ] ; // session id and serial number
95
+ console . log ( `initSession invoked for session and serial number: ${ sidSer } ` ) ;
92
96
callbackFn ( ) ;
93
97
} ) ;
94
98
}
@@ -125,9 +129,13 @@ async function handleRequest(request, response) {
125
129
try {
126
130
// Get a connection from the default connection pool
127
131
connection = await oracledb . getConnection ( ) ;
128
- const sql = `SELECT CURRENT_TIMESTAMP, SYS_CONTEXT('USERENV','SID') FROM DUAL` ;
132
+
133
+ const sql = `SELECT UNIQUE CURRENT_TIMESTAMP, sid||'-'||serial#
134
+ FROM v$session_connect_info
135
+ WHERE sid = SYS_CONTEXT('USERENV', 'SID')` ;
136
+
129
137
const result = await connection . execute ( sql ) ;
130
- console . log ( `Query at time ${ result . rows [ 0 ] [ 0 ] } used session ${ result . rows [ 0 ] [ 1 ] } ` ) ;
138
+ console . log ( `Query at ${ result . rows [ 0 ] [ 0 ] } used session and serial number ${ result . rows [ 0 ] [ 1 ] } ` ) ;
131
139
} catch ( err ) {
132
140
console . error ( err . message ) ;
133
141
} finally {
0 commit comments