Skip to content

Commit 9ed6ea1

Browse files
committed
Test Object attribute names with embeded special characters
1 parent 32dcdca commit 9ed6ea1

File tree

3 files changed

+112
-2
lines changed

3 files changed

+112
-2
lines changed

test/dbObject11.js

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. */
2+
3+
/******************************************************************************
4+
*
5+
* You may not use the identified files except in compliance with the Apache
6+
* License, Version 2.0 (the "License.")
7+
*
8+
* You may obtain a copy of the License at
9+
* http://www.apache.org/licenses/LICENSE-2.0.
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
*
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* NAME
19+
* 210. dbObject11.js
20+
*
21+
* DESCRIPTION
22+
* DB Objects contain PL/SQL methods.
23+
*
24+
*****************************************************************************/
25+
'use strict';
26+
27+
const oracledb = require('oracledb');
28+
const should = require('should');
29+
const dbconfig = require('./dbconfig.js');
30+
const testsUtil = require('./testsUtil.js');
31+
32+
describe('210. dbObject11.js', () => {
33+
34+
let conn;
35+
const TYPE = 'NODB_RV_FIELD_TYP';
36+
const TABLE = 'NODB_TAB_MYOTAB';
37+
38+
before(async () => {
39+
try {
40+
conn = await oracledb.getConnection(dbconfig);
41+
42+
let sql =`
43+
CREATE OR REPLACE TYPE ${TYPE} AS OBJECT (
44+
field_name VARCHAR2(20),
45+
number$$value NUMBER,
46+
number##value NUMBER,
47+
"hi &coder" VARCHAR2(20)
48+
);`;
49+
await conn.execute(sql);
50+
51+
sql =`
52+
CREATE TABLE ${TABLE} (
53+
c1 ${TYPE}
54+
)`;
55+
let plsql = testsUtil.sqlCreateTable(TABLE, sql);
56+
await conn.execute(plsql);
57+
58+
sql = `INSERT INTO ${TABLE} VALUES (:a)`;
59+
let binds ={
60+
a: {
61+
type: TYPE,
62+
val: {
63+
FIELD_NAME: 'abc',
64+
NUMBER$$VALUE: 123,
65+
'NUMBER##VALUE': 456,
66+
'hi &coder': 'node-oracledb'
67+
}
68+
}
69+
};
70+
let result = await conn.execute(sql, binds);
71+
should.strictEqual(result.rowsAffected, 1);
72+
73+
} catch(err) {
74+
should.not.exist(err);
75+
}
76+
}); // before()
77+
78+
after(async () => {
79+
try {
80+
let sql = `DROP TABLE ${TABLE} PURGE`;
81+
await conn.execute(sql);
82+
83+
sql = `DROP TYPE ${TYPE}`;
84+
await conn.execute(sql);
85+
86+
await conn.close();
87+
} catch(err) {
88+
should.not.exist(err);
89+
}
90+
}); // after()
91+
92+
it('210.1 Attribute names with embedded "$", "#", "&" and spaces', async () => {
93+
try {
94+
const query = `SELECT * FROM ${TABLE}`;
95+
const opts = { outFormat: oracledb.OBJECT };
96+
const result = await conn.execute(query, [], opts );
97+
98+
should.strictEqual(result.rows[0].C1.NUMBER$$VALUE, 123);
99+
should.strictEqual(result.rows[0].C1['NUMBER##VALUE'], 456);
100+
should.strictEqual(result.rows[0].C1['hi &coder'], 'node-oracledb');
101+
102+
} catch (err) {
103+
should.not.exist(err);
104+
}
105+
}); // 210.1
106+
});

test/list.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4559,4 +4559,7 @@ oracledb.OUT_FORMAT_OBJECT and resultSet = true
45594559
209. dbObject10.js
45604560
209.1 DB Objects which contain PL/SQL methods
45614561
209.2 By default, JavaScript Object toString() returns "[object type]"
4562-
209.3 The Object literal and JSON.stringify()
4562+
209.3 The Object literal and JSON.stringify()
4563+
4564+
210. dbObject11.js
4565+
210.1 Attribute names with embedded "$", "#", "&" and spaces

test/opts/mocha.opts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,4 +233,5 @@ test/dbObject6.js
233233
test/dbObject7.js
234234
test/dbObject8.js
235235
test/dbObject9.js
236-
test/dbObject10.js
236+
test/dbObject10.js
237+
test/dbObject11.js

0 commit comments

Comments
 (0)