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
+ } ) ;
0 commit comments