-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathconnProps.js
245 lines (210 loc) · 7.73 KB
/
connProps.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
/* Copyright (c) 2019, 2025, Oracle and/or its affiliates. */
/******************************************************************************
*
* This software is dual-licensed to you under the Universal Permissive License
* (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License
* 2.0 as shown at https://www.apache.org/licenses/LICENSE-2.0. You may choose
* either license.
*
* If you elect to accept the software under the Apache License, Version 2.0,
* the following applies:
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* NAME
* 193. connProps.js
*
* DESCRIPTION
* Test the "connection.clientInfo" and "connection.dbOp" properties.
* These tests requires DBA privilege.
*
*****************************************************************************/
'use strict';
const oracledb = require('oracledb');
const assert = require('assert');
const dbConfig = require('./dbconfig.js');
const testsUtil = require('./testsUtil.js');
describe('193. connProps.js', function() {
let isRunnable = false;
before(async function() {
const preps = await testsUtil.checkPrerequisites();
if (preps && dbConfig.test.DBA_PRIVILEGE) {
isRunnable = true;
}
if (!isRunnable) {
this.skip();
} else {
const dbaConfig = {
user: dbConfig.test.DBA_user,
password: dbConfig.test.DBA_password,
connectString: dbConfig.connectString,
privilege: oracledb.SYSDBA,
};
const dbaConnection = await oracledb.getConnection(dbaConfig);
const conn = await oracledb.getConnection(dbConfig);
const user = await testsUtil.getUser(conn);
const sql = `GRANT SELECT ANY DICTIONARY TO ${user}`;
await dbaConnection.execute(sql);
await conn.close();
await dbaConnection.close();
}
}); // before()
it('193.1 the default values of clientInfo and dbOp are null', async () => {
const conn = await oracledb.getConnection(dbConfig);
assert.strictEqual(conn.clientInfo, null);
assert.strictEqual(conn.dbOp, null);
await conn.close();
}); // 193.1
it('193.2 clientInfo and dbOp are write-only properties', async () => {
const conn = await oracledb.getConnection(dbConfig);
conn.clientInfo = 'nodb_193_2';
conn.dbOp = 'nodb_193_2';
assert.strictEqual(conn.clientInfo, null);
assert.strictEqual(conn.dbOp, null);
await conn.close();
}); // 193.2
it('193.3 check the results of setter()', async () => {
const conn = await oracledb.getConnection(dbConfig);
const t_clientInfo = "My demo application";
const t_dbOp = "Billing";
conn.clientInfo = t_clientInfo;
conn.dbOp = t_dbOp;
const sqlOne = `SELECT sys_context('userenv', 'client_info') FROM dual`;
let result = await conn.execute(sqlOne);
assert.strictEqual(result.rows[0][0], t_clientInfo);
const sqlTwo = `SELECT dbop_name FROM v$sql_monitor \
WHERE sid = sys_context('userenv', 'sid') \
AND status = 'EXECUTING'`;
result = await conn.execute(sqlTwo);
assert.strictEqual(result.rows[0][0], t_dbOp);
// Change the values and check quried results again
const k_clientInfo = "Demo Two";
const k_dbOp = "Billing Two";
conn.clientInfo = k_clientInfo;
conn.dbOp = k_dbOp;
result = await conn.execute(sqlOne);
assert.strictEqual(result.rows[0][0], k_clientInfo);
result = await conn.execute(sqlTwo);
assert.strictEqual(result.rows[0][0], k_dbOp);
await conn.close();
}); // 193.3
it('193.4 Negative - invalid values', async () => {
const conn = await oracledb.getConnection(dbConfig);
// Numeric values
assert.throws(
() => {
conn.clientInfo = 3;
},
/NJS-004:/
);
assert.throws(
() => {
conn.dbOp = 4;
},
/NJS-004:/
);
// NaN
assert.throws(
() => {
conn.clientInfo = NaN;
},
/NJS-004:/
);
assert.throws(
() => {
conn.dbOp = NaN;
},
/NJS-004:/
);
// undefined
assert.throws(
() => {
conn.clientInfo = undefined;
},
/NJS-004:/
);
assert.throws(
() => {
conn.dbOp = undefined;
},
/NJS-004:/
);
await conn.close();
}); // 193.4
it('193.5 Oracle Database service name associated with the connection', async () => {
const conn = await oracledb.getConnection(dbConfig);
const query = "SELECT upper(sys_context('userenv', 'service_name')) FROM DUAL";
const result = await conn.execute(query);
assert.deepStrictEqual(result.rows[0][0], conn.serviceName.toUpperCase());
await conn.close();
}); // 193.5
it('193.6 Oracle Database dbname associated with the connection', async () => {
let query;
if (!oracledb.thin) {
// on thick mode for CDB based DB's, the CDB name is returned.
query = `SELECT upper(NAME) FROM v$database`;
} else {
query = "SELECT GLOBAL_NAME FROM GLOBAL_NAME";
}
const conn = await oracledb.getConnection(dbConfig);
const result = await conn.execute(query);
assert.deepStrictEqual(result.rows[0][0], conn.dbName.toUpperCase());
await conn.close();
}); // 193.6
it('193.7 Oracle Database db domain associated with the connection', async () => {
const conn = await oracledb.getConnection(dbConfig);
const query = "SELECT upper(VALUE) FROM v$parameter WHERE name='db_domain'";
const result = await conn.execute(query);
if (result.rows[0][0]) {
assert.deepStrictEqual(result.rows[0][0], conn.dbDomain.toUpperCase());
} else {
assert.deepStrictEqual(conn.dbDomain, '');
}
await conn.close();
}); // 193.7
it('193.8 maximum cursors that can be opened on a connection', async () => {
const conn = await oracledb.getConnection(dbConfig);
const query = "SELECT value FROM v$parameter WHERE name='open_cursors'";
const result = await conn.execute(query);
assert.deepStrictEqual(Number(result.rows[0][0]), conn.maxOpenCursors);
await conn.close();
}); // 193.8
it('193.9 transactionInProgress = false on a connection for query', async () => {
const conn = await oracledb.getConnection(dbConfig);
const query = "SELECT * FROM DUAL";
await conn.execute(query);
assert.strictEqual(conn.transactionInProgress, false);
await conn.close();
}); // 193.9
it('193.10 transactionInProgress = true on a connection', async () => {
const conn = await oracledb.getConnection(dbConfig);
const TABLE = 'nodb_emp';
const createSql = `CREATE TABLE ${TABLE} (id number)`;
assert.strictEqual(conn.transactionInProgress, false);
await testsUtil.createTable(conn, TABLE, createSql);
assert.strictEqual(conn.transactionInProgress, false);
const sql = `INSERT INTO ${TABLE} VALUES(1)`;
await conn.execute(sql);
assert.strictEqual(conn.transactionInProgress, true);
await conn.commit();
assert.strictEqual(conn.transactionInProgress, false);
await conn.execute(`DROP TABLE ${TABLE} PURGE`);
await conn.close();
}); // 193.10
it('193.11 maximum identifier length', async () => {
const conn = await oracledb.getConnection(dbConfig);
if (conn.maxIdentifierLength)
assert.strictEqual(typeof conn.maxIdentifierLength, "number");
await conn.close();
}); // 193.11
});