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
+ * 220. examineOwnedProperties.js
20
+ *
21
+ * DESCRIPTION
22
+ * Add this test from GitHub issue 1129 to prevent regression.
23
+ * https://github.com/oracle/node-oracledb/issues/1129
24
+ *
25
+ *****************************************************************************/
26
+ 'use strict' ;
27
+
28
+ const oracledb = require ( 'oracledb' ) ;
29
+ const should = require ( 'should' ) ;
30
+ const dbconfig = require ( './dbconfig.js' ) ;
31
+ const testsUtil = require ( './testsUtil.js' ) ;
32
+
33
+ describe ( '220. examineOwnedProperties.js' , ( ) => {
34
+
35
+ let conn ;
36
+ const TABLE = "nodb_tab_rating" ;
37
+
38
+ before ( async ( ) => {
39
+ try {
40
+ conn = await oracledb . getConnection ( dbconfig ) ;
41
+
42
+ let sql = `
43
+ CREATE TABLE ${ TABLE } (
44
+ "RATE_TIME" VARCHAR2(32),
45
+ "RATE_USER" VARCHAR2(128),
46
+ "ITEM_PRICE" NUMBER,
47
+ "RATING" VARCHAR2(4000)
48
+ )
49
+ ` ;
50
+ let plsql = testsUtil . sqlCreateTable ( TABLE , sql ) ;
51
+ await conn . execute ( plsql ) ;
52
+ } catch ( err ) {
53
+ should . not . exist ( err ) ;
54
+ }
55
+ } ) ; // before()
56
+
57
+ after ( async ( ) => {
58
+ try {
59
+ let sql = `DROP TABLE ${ TABLE } PURGE` ;
60
+ await conn . execute ( sql ) ;
61
+ conn . close ( ) ;
62
+ } catch ( err ) {
63
+ should . not . exist ( err ) ;
64
+ }
65
+ } ) ; // after()
66
+
67
+ it ( '220.1 Only examine "owned" properties on objects' , async ( ) => {
68
+ try {
69
+ const sql = `
70
+ MERGE INTO ${ TABLE } R USING (
71
+ SELECT
72
+ :item_price as itemPrice,
73
+ :rate_time as rateTime,
74
+ :rate_user as rateUser,
75
+ :rating as rating
76
+ FROM DUAL ) T ON (
77
+ R.RATE_TIME = T.rateTime
78
+ AND R.RATE_USER = T.rateUser
79
+ ) WHEN MATCHED THEN UPDATE SET
80
+ R.ITEM_PRICE = T.itemPrice
81
+ , R.RATING = T.rating
82
+ WHEN NOT MATCHED THEN INSERT (
83
+ RATE_TIME
84
+ , RATE_USER
85
+ , ITEM_PRICE
86
+ , RATING
87
+ ) VALUES (
88
+ T.rateTime
89
+ , T.rateUser
90
+ , T.itemPrice
91
+ , T.rating
92
+ )
93
+ ` ;
94
+ const data = [
95
+ { "rate_user" : "Bob" ,
96
+ "rate_time" : "2019-07-26 19:42:36" ,
97
+ "item_price" :338 ,
98
+ "rating" :"I like it"
99
+ } ,
100
+ { "rate_user" : "Alice" ,
101
+ "rate_time" : "2019-07-26 19:42:36" ,
102
+ "item_price" :338 ,
103
+ "rating" :"I like it too"
104
+ }
105
+ ] ;
106
+ const options = {
107
+ autoCommit : true ,
108
+ bindDefs : {
109
+ item_price : { type : oracledb . NUMBER } ,
110
+ rate_time : { type : oracledb . STRING , maxSize : 32 } ,
111
+ rate_user : { type : oracledb . STRING , maxSize : 128 } ,
112
+ rating : { type : oracledb . STRING , maxSize : 4000 } ,
113
+ }
114
+ } ;
115
+
116
+ Object . prototype . noop = ( ) => { } ;
117
+
118
+ await conn . executeMany ( sql , data , options ) ;
119
+
120
+ } catch ( err ) {
121
+ should . not . exist ( err ) ;
122
+ }
123
+ } ) ; // 220.1
124
+ } ) ;
0 commit comments