-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathdbType02.js
163 lines (137 loc) · 4.79 KB
/
dbType02.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
/* Copyright (c) 2019, 2022, 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
* 227. dbType02.js
*
* DESCRIPTION
* Roundtrip tests of binding data of types DB_TYPE_*.
*
*****************************************************************************/
'use strict';
const oracledb = require('oracledb');
const assert = require('assert');
const dbConfig = require('./dbconfig.js');
const testsUtil = require('./testsUtil.js');
describe('227. dbType02.js', () => {
let conn;
before(async () => {
conn = await oracledb.getConnection(dbConfig);
});
after(async () => {
await conn.close();
});
async function CreateTable(TABLE, TYPE) {
const sql = `
CREATE TABLE ${TABLE} (id NUMBER, content ${TYPE})
`;
const plsql = testsUtil.sqlCreateTable(TABLE, sql);
await conn.execute(plsql);
} // CreateTable()
async function DropTable(TABLE) {
const sql = `DROP TABLE ${TABLE} PURGE`;
await conn.execute(sql);
} // DropTable
async function VerifyString(TABLE, TYPE, NODB_TYPE) {
await CreateTable(TABLE, TYPE);
let sql = `INSERT INTO ${TABLE} VALUES (:i, :c)`;
const bindArray = [
{ i: 1, c: 'node-oracledb'},
{ i: 2, c: ''},
{ i: 3, c: null}
];
const opts = {
autoCommit: true,
bindDefs: {
i: { type: oracledb.DB_TYPE_NUMBER },
c: { type: NODB_TYPE, maxSize: 100 }
}
};
await conn.executeMany(sql, bindArray, opts);
sql = `SELECT * FROM ${TABLE} ORDER BY ID`;
const result = await conn.execute(sql);
const expects = 'node-oracledb';
assert.strictEqual(result.rows[0][1].trim(), expects);
assert.strictEqual(result.rows[1][1], null);
assert.strictEqual(result.rows[1][1], null);
await DropTable(TABLE);
} // VerifyString()
async function VerifyDate(TABLE, TYPE, NODB_TYPE) {
await CreateTable(TABLE, TYPE);
let sql = `INSERT INTO ${TABLE} VALUES (:i, :c)`;
const dateInVal = new Date();
const bindArray = [
{ i: 1, c: dateInVal },
{ i: 2, c: null }
];
const opts = {
autoCommit: true,
bindDefs: {
i: { type: oracledb.DB_TYPE_NUMBER },
c: { type: NODB_TYPE, maxSize: 200 }
}
};
await conn.executeMany(sql, bindArray, opts);
sql = `SELECT * FROM ${TABLE} ORDER BY ID`;
const result = await conn.execute(sql);
assert.strictEqual(testsUtil.isDate(result.rows[0][1]), true);
assert.strictEqual(result.rows[1][1], null);
await DropTable(TABLE);
}
it('227.1 DB_TYPE_VARCHAR', async () => {
const tableName = 'nodb_type_varchar';
const type = 'VARCHAR2(50)';
const dbType = oracledb.DB_TYPE_VARCHAR;
await VerifyString(tableName, type, dbType);
}); // 227.1
it('227.2 DB_TYPE_CHAR', async () => {
const tableName = 'nodb_type_char';
const type = 'CHAR(2000)';
const dbType = oracledb.DB_TYPE_CHAR;
await VerifyString(tableName, type, dbType);
}); // 227.2
it('227.3 DB_TYPE_NVARCHAR', async () => {
const tableName = 'nodb_type_nvarchar';
const type = 'NVARCHAR2(2000)';
const dbType = oracledb.DB_TYPE_NVARCHAR;
await VerifyString(tableName, type, dbType);
}); // 227.3
it('227.4 DB_TYPE_NCHAR', async () => {
const tableName = 'nodb_type_nchar';
const type = 'NCHAR(1000)';
const dbType = oracledb.DB_TYPE_NCHAR;
await VerifyString(tableName, type, dbType);
}); // 227.4
it('227.5 DB_TYPE_DATE', async () => {
const tableName = 'nodb_type_date';
const type = 'DATE';
const dbType = oracledb.DB_TYPE_DATE;
await VerifyDate(tableName, type, dbType);
}); // 227.5
it('227.6 DB_TYPE_TIMESTAMP_LTZ', async () => {
const tableName = 'nodb_type_date';
const type = 'TIMESTAMP WITH LOCAL TIME ZONE';
const dbType = oracledb.DB_TYPE_TIMESTAMP_LTZ;
await VerifyDate(tableName, type, dbType);
}); // 227.6
});