-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathlobProperties1.js
262 lines (241 loc) · 8.39 KB
/
lobProperties1.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
/* Copyright (c) 2015, 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
* 62. lobProperties1.js
*
* DESCRIPTION
* Testing getters and setters for LOB class.
* This test aims to increase the code coverage rate.
*
*****************************************************************************/
'use strict';
const oracledb = require('oracledb');
const fs = require('fs');
const assert = require('assert');
const dbConfig = require('./dbconfig.js');
describe('62. lobProperties1.js', function() {
const tableName = "nodb_tab_mylobprops";
let connection;
const sqlSelect = "SELECT * FROM " + tableName + " WHERE id = :i";
let defaultChunkSize = null;
before('prepare table and LOB data', async function() {
const sqlCreateTab =
" BEGIN "
+ " DECLARE "
+ " e_table_missing EXCEPTION; "
+ " PRAGMA EXCEPTION_INIT(e_table_missing, -00942); "
+ " BEGIN "
+ " EXECUTE IMMEDIATE ('DROP TABLE " + tableName + " PURGE'); "
+ " EXCEPTION "
+ " WHEN e_table_missing "
+ " THEN NULL; "
+ " END; "
+ " EXECUTE IMMEDIATE (' "
+ " CREATE TABLE " + tableName + " ( "
+ " id NUMBER, c CLOB, b BLOB "
+ " ) "
+ " '); "
+ " END; ";
const sqlInsert = "INSERT INTO " + tableName + " VALUES (:i, EMPTY_CLOB(), EMPTY_BLOB()) "
+ " RETURNING c, b INTO :clob, :blob";
const bindVar =
{
i: 1,
clob: { type: oracledb.CLOB, dir: oracledb.BIND_OUT },
blob: { type: oracledb.BLOB, dir: oracledb.BIND_OUT }
};
const clobFileName = './test/clobexample.txt';
const blobFileName = './test/fuzzydinosaur.jpg';
connection = await oracledb.getConnection(dbConfig);
await connection.execute(sqlCreateTab);
let result = await connection.execute(sqlInsert, bindVar);
let clob = result.outBinds.clob[0];
let blob = result.outBinds.blob[0];
const clobStream = fs.createReadStream(clobFileName);
const blobStream = fs.createReadStream(blobFileName);
clobStream.pipe(clob);
blobStream.pipe(blob);
await new Promise((resolve, reject) => {
clobStream.on('error', reject);
blobStream.on('error', reject);
clob.on('error', reject);
blob.on('error', reject);
const waitForClob = async function() {
await new Promise((resolve) => {
clob.on('finish', resolve);
});
};
const waitForBlob = async function() {
await new Promise((resolve) => {
blob.on('finish', resolve);
});
};
Promise.all([waitForClob(), waitForBlob()]).then(resolve);
});
result = await connection.execute(sqlSelect, { i: 1 });
clob = result.rows[0][1];
blob = result.rows[0][2];
defaultChunkSize = clob.chunkSize;
await blob.close();
await clob.close();
}); // before
after(async function() {
await connection.execute("DROP TABLE " + tableName + " PURGE");
await connection.close();
});
it('62.1 chunkSize (read-only)', async function() {
const result = await connection.execute(sqlSelect, { i: 1 });
const clob = result.rows[0][1];
const blob = result.rows[0][2];
const t1 = clob.chunkSize;
const t2 = blob.chunkSize;
assert.strictEqual(typeof t1, 'number');
assert.strictEqual(typeof t2, 'number');
assert.strictEqual(t1, t2);
defaultChunkSize = clob.chunkSize;
assert.throws(
() => clob.chunkSize = t1 + 1,
/TypeError: Cannot set property/
);
assert.throws(
() => blob.chunkSize = t2 + 1,
/TypeError: Cannot set property/
);
await clob.close();
await blob.close();
}); // 62.1
it('62.2 length (read-only)', async function() {
const result = await connection.execute(sqlSelect, { i: 1 });
const clob = result.rows[0][1];
const blob = result.rows[0][2];
const t1 = clob.length;
const t2 = blob.length;
assert.throws(
() => clob.length = t1 + 1,
/TypeError: Cannot set property/
);
assert.throws(
() => blob.length = t2 + 1,
/TypeError: Cannot set property/
);
await clob.close();
await blob.close();
}); // 62.2
it('62.3 pieceSize -default value is chunkSize', async function() {
const result = await connection.execute(sqlSelect, { i: 1 });
const clob = result.rows[0][1];
const blob = result.rows[0][2];
assert.strictEqual(clob.pieceSize, defaultChunkSize);
assert.strictEqual(blob.pieceSize, defaultChunkSize);
await clob.close();
await blob.close();
}); // 62.3
it('62.4 pieceSize - can be increased', async function() {
const result = await connection.execute(sqlSelect, { i: 1 });
const clob = result.rows[0][1];
const blob = result.rows[0][2];
const newValue = clob.pieceSize * 5;
clob.pieceSize = clob.pieceSize * 5;
blob.pieceSize = blob.pieceSize * 5;
assert.strictEqual(clob.pieceSize, newValue);
assert.strictEqual(blob.pieceSize, newValue);
await clob.close();
await blob.close();
}); // 62.4
it('62.5 pieceSize - can be decreased', async function() {
if (defaultChunkSize <= 500)
return this.skip();
const result = await connection.execute(sqlSelect, { i: 1 });
const clob = result.rows[0][1];
const blob = result.rows[0][2];
const newValue = clob.pieceSize - 500;
clob.pieceSize -= 500;
blob.pieceSize -= 500;
assert.strictEqual(clob.pieceSize, newValue);
assert.strictEqual(blob.pieceSize, newValue);
await clob.close();
await blob.close();
}); // 62.5
it('62.6 pieceSize - can be zero', async function() {
const result = await connection.execute(sqlSelect, { i: 1 });
const clob = result.rows[0][1];
const blob = result.rows[0][2];
clob.pieceSize = 0;
blob.pieceSize = 0;
assert.strictEqual(clob.pieceSize, 0);
assert.strictEqual(blob.pieceSize, 0);
await clob.close();
await blob.close();
}); // 62.6
it('62.7 pieceSize - cannot be less than zero', async function() {
const result = await connection.execute(sqlSelect, { i: 1 });
const clob = result.rows[0][1];
const blob = result.rows[0][2];
assert.throws(
() => clob.pieceSize = -100,
/NJS-004:/
);
await clob.close();
await blob.close();
}); // 62.7
it('62.8 pieceSize - cannot be null', async function() {
const result = await connection.execute(sqlSelect, { i: 1 });
const clob = result.rows[0][1];
const blob = result.rows[0][2];
assert.throws(
() => clob.pieceSize = null,
/NJS-004:/
);
await clob.close();
await blob.close();
}); // 62.8
it('62.9 pieceSize - must be a number', async function() {
const result = await connection.execute(sqlSelect, { i: 1 });
const clob = result.rows[0][1];
const blob = result.rows[0][2];
assert.throws(
() => clob.pieceSize = NaN,
/NJS-004:/
);
await clob.close();
await blob.close();
}); // 62.9
it('62.10 type (read-only)', async function() {
const result = await connection.execute(sqlSelect, { i: 1 });
const clob = result.rows[0][1];
const blob = result.rows[0][2];
assert.strictEqual(clob.type, oracledb.CLOB);
assert.strictEqual(blob.type, oracledb.BLOB);
assert.throws(
() => clob.type = oracledb.BLOB,
/TypeError: Cannot set/
);
assert.throws(
() => blob.type = oracledb.CLOB,
/TypeError: Cannot set/
);
await clob.close();
await blob.close();
}); // 62.10
});