Skip to content

Commit 1d0ee74

Browse files
committed
Add tests for 6.7.1
1 parent f567c9d commit 1d0ee74

File tree

6 files changed

+238
-62
lines changed

6 files changed

+238
-62
lines changed

test/columnMetadata.js

+206-52
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ describe('9. columnMetadata.js', function() {
166166
assert.strictEqual(result.rows[0][0], 'Finance');
167167
}); // 9.1.8
168168

169-
it('9.1.9 works with a SQL WITH statement', async function() {
169+
it('9.1.9 SQL WITH statement', async function() {
170170
const sqlWith = "WITH nodb_dep AS " +
171171
"(SELECT * FROM nodb_cmd WHERE location_id < 2000) " +
172172
"SELECT * FROM nodb_dep WHERE department_id > 50 ORDER BY department_id";
@@ -186,43 +186,80 @@ describe('9. columnMetadata.js', function() {
186186
assert.strictEqual(result.metaData[2].name, 'MANAGER_ID');
187187
assert.strictEqual(result.metaData[3].name, 'LOCATION_ID');
188188
await result.resultSet.close();
189-
});
190-
}); // 9.1
189+
}); // 9.1.10
190+
191+
it('9.1.11 column aliases in SELECT', async function() {
192+
const result = await connection.execute(`SELECT department_id AS dep_id, department_name AS dep_name FROM nodb_cmd`);
193+
assert.strictEqual(result.metaData[0].name, 'DEP_ID');
194+
assert.strictEqual(result.metaData[1].name, 'DEP_NAME');
195+
}); // 9.1.11
196+
197+
it('9.1.12 expressions in SELECT', async function() {
198+
const result = await connection.execute(`SELECT department_id + 1 AS dep_increment, UPPER(department_name) AS dep_upper FROM nodb_cmd`);
199+
assert.strictEqual(result.metaData[0].name, 'DEP_INCREMENT');
200+
assert.strictEqual(result.metaData[1].name, 'DEP_UPPER');
201+
}); // 9.1.12
202+
203+
it('9.1.13 retrieves metaData for columns from subqueries', async function() {
204+
const result = await connection.execute(`
205+
SELECT subq.department_name, subq.manager_id
206+
FROM (SELECT department_name, manager_id FROM nodb_cmd WHERE location_id = 1500) subq`);
207+
assert.strictEqual(result.metaData[0].name, 'DEPARTMENT_NAME');
208+
assert.strictEqual(result.metaData[1].name, 'MANAGER_ID');
209+
}); // 9.1.13
210+
211+
it('9.1.14 UNION queries', async function() {
212+
const result = await connection.execute(`
213+
SELECT department_id, department_name FROM nodb_cmd
214+
UNION
215+
SELECT 100 AS department_id, 'Finance' AS department_name FROM dual`);
216+
assert.strictEqual(result.metaData[0].name, 'DEPARTMENT_ID');
217+
assert.strictEqual(result.metaData[1].name, 'DEPARTMENT_NAME');
218+
}); // 9.1.14
219+
220+
it('9.1.15 JOINs', async function() {
221+
const result = await connection.execute(`
222+
SELECT a.department_id, a.department_name, b.location_id
223+
FROM nodb_cmd a
224+
JOIN nodb_cmd b ON a.department_id = b.department_id`);
225+
assert.strictEqual(result.metaData[0].name, 'DEPARTMENT_ID');
226+
assert.strictEqual(result.metaData[1].name, 'DEPARTMENT_NAME');
227+
assert.strictEqual(result.metaData[2].name, 'LOCATION_ID');
228+
}); // 9.1.15
229+
230+
it('9.1.16 nested function calls in column names', async function() {
231+
const result = await connection.execute(`
232+
SELECT
233+
UPPER(department_name) AS upper_dept_name,
234+
LOWER(TRIM(department_name)) AS lower_dept_name
235+
FROM nodb_cmd
236+
`);
237+
238+
assert.strictEqual(result.metaData[0].name, 'UPPER_DEPT_NAME');
239+
assert.strictEqual(result.metaData[1].name, 'LOWER_DEPT_NAME');
240+
}); // 9.1.16
241+
});
191242

192243
describe('9.2 case sensitive', function() {
193244
it('9.2.1 works for tables whose column names were created case sensitively', async function() {
194-
const proc = "BEGIN \n" +
195-
" DECLARE \n" +
196-
" e_table_missing EXCEPTION; \n" +
197-
" PRAGMA EXCEPTION_INIT(e_table_missing, -00942);\n " +
198-
" BEGIN \n" +
199-
" EXECUTE IMMEDIATE ('DROP TABLE nodb_casesensitive PURGE'); \n" +
200-
" EXCEPTION \n" +
201-
" WHEN e_table_missing \n" +
202-
" THEN NULL; \n" +
203-
" END; \n" +
204-
" EXECUTE IMMEDIATE (' \n" +
205-
" CREATE TABLE nodb_casesensitive ( \n" +
206-
" id NUMBER, \n" +
207-
' "nAme" VARCHAR2(20) \n' +
208-
" ) \n" +
209-
" '); \n" +
210-
"END; ";
211-
212-
await connection.execute(proc);
245+
const tableName = "nodb_casesensitive";
246+
const sql = ` CREATE TABLE ${tableName} (
247+
id NUMBER,
248+
"nAme" VARCHAR2(20))`;
249+
const plsql = testsUtil.sqlCreateTable(tableName, sql);
250+
await connection.execute(plsql);
213251
const result = await connection.execute("SELECT * FROM nodb_casesensitive");
214252
assert.strictEqual(result.rows.length, 0);
215253
assert.strictEqual(result.metaData[0].name, 'ID');
216254
assert.strictEqual(result.metaData[1].name, 'nAme');
217-
await connection.execute("DROP TABLE nodb_casesensitive PURGE");
255+
await connection.execute(testsUtil.sqlDropTable(tableName));
218256
});
219257
}); // 9.2
220258

221259
describe('9.3 Large number of columns', function() {
222260
let columns_string;
223261
const tableName = "nodb_large_columns";
224262
const sqlSelect = "SELECT * FROM " + tableName;
225-
const sqlDrop = testsUtil.sqlDropTable(tableName);
226263

227264
function genColumns(size, dbType) {
228265
const buffer = [];
@@ -238,10 +275,13 @@ describe('9. columnMetadata.js', function() {
238275

239276
after(async function() {
240277
oracledb.fetchAsString = [];
241-
await connection.execute(sqlDrop);
278+
await connection.execute(testsUtil.sqlDropTable(tableName));
242279
});
243280

244-
it('9.3.1 works with a large number of columns', async function() {
281+
it('9.3.1 large number of columns', async function() {
282+
if (await testsUtil.cmanTdmCheck()) {
283+
this.skip('Test skipped because CMAN TDM is enabled.');
284+
}
245285
const column_size = 300;
246286
columns_string = genColumns(column_size, " NUMBER");
247287

@@ -256,7 +296,7 @@ describe('9. columnMetadata.js', function() {
256296
for (let i = 0; i < column_size; i++) {
257297
assert.strictEqual(result.metaData[i].name, 'COLUMN_' + i);
258298
}
259-
await connection.execute(sqlDrop);
299+
await connection.execute(testsUtil.sqlDropTable(tableName));
260300

261301
// check CLOB type (GH Issue 1642)
262302
columns_string = genColumns(column_size, " CLOB");
@@ -266,10 +306,13 @@ describe('9. columnMetadata.js', function() {
266306
for (let i = 0; i < column_size; i++) {
267307
assert.strictEqual(result.metaData[i].name, 'COLUMN_' + i);
268308
}
269-
await connection.execute(sqlDrop);
309+
await connection.execute(testsUtil.sqlDropTable(tableName));
270310
});
271311

272-
it('9.3.2 works with re-executes with multiple packet response', async function() {
312+
it('9.3.2 re-executes with multiple packet response', async function() {
313+
if (await testsUtil.cmanTdmCheck()) {
314+
this.skip('Test skipped because CMAN TDM is enabled.');
315+
}
273316
const column_size = 50;
274317
const numRows = 5;
275318
oracledb.fetchAsString = [oracledb.CLOB];
@@ -319,40 +362,30 @@ describe('9. columnMetadata.js', function() {
319362
}
320363
}
321364

322-
await connection.execute(sqlDrop);
365+
await connection.execute(testsUtil.sqlDropTable(tableName));
323366
});
324367
}); // 9.3
325368

326369
describe('9.4 single character column', function() {
327370

328-
it('9.4.1 works with column names consisting of single characters', async function() {
371+
it('9.4.1 column names consisting of single characters', async function() {
329372
const tableName = "nodb_single_char";
330-
const sqlCreate =
331-
"BEGIN \n" +
332-
" DECLARE \n" +
333-
" e_table_missing EXCEPTION; \n" +
334-
" PRAGMA EXCEPTION_INIT(e_table_missing, -00942); \n" +
335-
" BEGIN \n" +
336-
" EXECUTE IMMEDIATE ('DROP TABLE " + tableName + " PURGE'); \n" +
337-
" EXCEPTION \n" +
338-
" WHEN e_table_missing \n" +
339-
" THEN NULL; \n" +
340-
" END; \n" +
341-
" EXECUTE IMMEDIATE (' \n" +
342-
" CREATE TABLE " + tableName + " ( \n" +
343-
" a VARCHAR2(20), \n" +
344-
' b VARCHAR2(20) \n' +
345-
" ) \n" +
346-
" '); \n" +
347-
"END; \n";
373+
374+
const sql = `
375+
CREATE TABLE ${tableName} (
376+
a VARCHAR2(20),
377+
b VARCHAR2(20)
378+
)
379+
`;
348380
const sqlSelect = "SELECT * FROM " + tableName;
349-
const sqlDrop = "DROP TABLE " + tableName + " PURGE";
350381

351-
await connection.execute(sqlCreate);
382+
const plsql = testsUtil.sqlCreateTable(tableName, sql);
383+
await connection.execute(plsql);
352384
const result = await connection.execute(sqlSelect);
353385
assert.strictEqual(result.metaData[0].name, 'A');
354386
assert.strictEqual(result.metaData[1].name, 'B');
355-
await connection.execute(sqlDrop);
387+
388+
await connection.execute(testsUtil.sqlDropTable(tableName));
356389
});
357390
}); // 9.4
358391

@@ -364,4 +397,125 @@ describe('9. columnMetadata.js', function() {
364397
assert.strictEqual(result.metaData[1].name, 'A_1');
365398
});
366399
});
400+
401+
describe('9.6 testing metaData with various column data types', function() {
402+
const tableName = "nodb_data_types";
403+
404+
before('create table with various data types', async function() {
405+
const proc = `
406+
BEGIN
407+
EXECUTE IMMEDIATE '
408+
CREATE TABLE ${tableName} (
409+
c1 NUMBER,
410+
c2 VARCHAR2(100),
411+
c3 DATE,
412+
c4 TIMESTAMP,
413+
c5 CLOB,
414+
c6 BLOB
415+
)';
416+
EXECUTE IMMEDIATE 'INSERT INTO ${tableName} VALUES (1, ''Test String'', SYSDATE, SYSTIMESTAMP, ''CLOB Test'', UTL_RAW.CAST_TO_RAW(''BLOB Test''))';
417+
END;`;
418+
419+
await connection.execute(proc);
420+
});
421+
422+
after('drop the table', async function() {
423+
await connection.execute(testsUtil.sqlDropTable(tableName));
424+
});
425+
426+
it('9.6.1 verifies column metaData for various data types', async function() {
427+
const result = await connection.execute(`SELECT * FROM ${tableName}`);
428+
const expectedMetaData = [
429+
{ name: 'C1', type: oracledb.DB_TYPE_NUMBER },
430+
{ name: 'C2', type: oracledb.DB_TYPE_VARCHAR },
431+
{ name: 'C3', type: oracledb.DB_TYPE_DATE },
432+
{ name: 'C4', type: oracledb.DB_TYPE_TIMESTAMP },
433+
{ name: 'C5', type: oracledb.DB_TYPE_CLOB },
434+
{ name: 'C6', type: oracledb.DB_TYPE_BLOB }
435+
];
436+
437+
assert.strictEqual(result.rows.length, 1);
438+
assert.strictEqual(result.metaData.length, 6);
439+
440+
result.metaData.forEach((col, index) => {
441+
assert.strictEqual(col.name, expectedMetaData[index].name);
442+
assert.strictEqual(col.dbType, expectedMetaData[index].type);
443+
});
444+
});
445+
});
446+
447+
describe('9.7 Complex Column Metadata Scenarios', function() {
448+
it('9.7.1 columns with special characters in names', async function() {
449+
const tableName = "nodb_special_chars";
450+
const sql = `
451+
CREATE TABLE ${tableName} (
452+
"column.with.dots" NUMBER,
453+
"column-with-hyphens" VARCHAR2(50),
454+
"column_with_underscores" DATE
455+
)
456+
`;
457+
458+
const plsql = testsUtil.sqlCreateTable(tableName, sql);
459+
await connection.execute(plsql);
460+
461+
const result = await connection.execute(`SELECT * FROM ${tableName}`);
462+
assert.strictEqual(result.metaData[0].name, 'column.with.dots');
463+
assert.strictEqual(result.metaData[1].name, 'column-with-hyphens');
464+
assert.strictEqual(result.metaData[2].name, 'column_with_underscores');
465+
await connection.execute(testsUtil.sqlDropTable(tableName));
466+
});
467+
468+
it('9.7.3 columns with very long names', async function() {
469+
// Skip the test for database versions <= 12.1.0.2.0 due to the 30-character limit on column names.
470+
if (connection.oracleServerVersion <= 1201000200) this.skip();
471+
472+
const tableName = "nodb_very_long_column_names";
473+
const sql = `
474+
CREATE TABLE ${tableName} (
475+
very_very_very_very_very_very_very_very_very_long_column_name_1 NUMBER,
476+
very_very_very_very_very_very_very_very_very_long_column_name_2 VARCHAR2(100)
477+
)
478+
`;
479+
480+
const plsql = testsUtil.sqlCreateTable(tableName, sql);
481+
await connection.execute(plsql);
482+
483+
const result = await connection.execute(`SELECT * FROM ${tableName}`);
484+
assert.strictEqual(result.metaData[0].name, 'VERY_VERY_VERY_VERY_VERY_VERY_VERY_VERY_VERY_LONG_COLUMN_NAME_1');
485+
assert.strictEqual(result.metaData[1].name, 'VERY_VERY_VERY_VERY_VERY_VERY_VERY_VERY_VERY_LONG_COLUMN_NAME_2');
486+
487+
await connection.execute(testsUtil.sqlDropTable(tableName));
488+
});
489+
});
490+
491+
describe('9.8 Metadata Type Precision and Scale', function() {
492+
it('9.8.1 should provide precision and scale for numeric columns', async function() {
493+
const tableName = "nodb_numeric_precision";
494+
const sql = `
495+
CREATE TABLE ${tableName} (
496+
decimal_col DECIMAL(10,2),
497+
number_col NUMBER(5,3),
498+
float_col FLOAT
499+
)
500+
`;
501+
502+
const plsql = testsUtil.sqlCreateTable(tableName, sql);
503+
await connection.execute(plsql);
504+
505+
const result = await connection.execute(`SELECT * FROM ${tableName}`);
506+
507+
// Check precision and scale for DECIMAL column
508+
assert.strictEqual(result.metaData[0].precision, 10);
509+
assert.strictEqual(result.metaData[0].scale, 2);
510+
511+
// Check precision and scale for NUMBER column
512+
assert.strictEqual(result.metaData[1].precision, 5);
513+
assert.strictEqual(result.metaData[1].scale, 3);
514+
515+
// Float columns might have different characteristics
516+
assert(result.metaData[2].precision !== undefined);
517+
518+
await connection.execute(testsUtil.sqlDropTable(tableName));
519+
});
520+
});
367521
});

test/ext/release-check-tests/databaseLink.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
* DML operations on different DataTypes with database link
3030
*
3131
* Grant Link Creation (sysdba):
32-
* CONNECT sys/knl_test7@<db_alias1> AS SYSDBA -- Connect as sysdba on database alias 1
32+
* CONNECT sys/<dba_password>@<db_alias1> AS SYSDBA -- Connect as sysdba on database alias 1
3333
* GRANT CREATE PUBLIC DATABASE LINK TO scott;
3434
* Connect as User (e.g. scott/tiger):
3535
* CONNECT scott/tiger@<db_alias1> -- Connect as regular user on alias 1
@@ -38,7 +38,7 @@
3838
* Set the Environment Variable NODE_ORACLEDB_CONNECTIONSTRING1
3939
*
4040
* Connect as sysdba (different database alias):
41-
* CONNECT sys/knl_test7@<db_alias2> AS SYSDBA -- Connect as sysdba on database alias 2
41+
* CONNECT sys/<dba_password>@<db_alias2> AS SYSDBA -- Connect as sysdba on database alias 2
4242
* Create Database Link:
4343
* CREATE DATABASE LINK link_name -- Replace with desired name
4444
* CONNECT TO scott IDENTIFIED BY tiger

test/ext/release-check-tests/edge-max-cases/jsonDMLBindLargeData.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ describe('9.jsonDMLBindLargeData.js', function() {
4747

4848
before(async function() {
4949
const credential = {
50-
user: process.env.NODE_ORACLEDB_DBA_USER || "sys",
51-
password: process.env.NODE_ORACLEDB_DBA_PASSWORD || "knl_test7",
50+
user: process.env.NODE_ORACLEDB_DBA_USER,
51+
password: process.env.NODE_ORACLEDB_DBA_PASSWORD,
5252
connectString: dbconfig.connectString,
5353
privilege: oracledb.SYSDBA
5454
};

test/ext/release-check-tests/edge-max-cases/jsonPLSQLBindLargeData.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ describe('10.jsonPLSQLBindLargeData.js', function() {
6161

6262
before(async function() {
6363
const credential = {
64-
user: "sys",
65-
password: "knl_test7",
64+
user: process.env.NODE_ORACLEDB_DBA_USER,
65+
password: process.env.NODE_ORACLEDB_DBA_PASSWORD,
6666
connectString: dbconfig.connectString,
6767
privilege: oracledb.SYSDBA
6868
};

0 commit comments

Comments
 (0)