Skip to content

Commit cbed304

Browse files
committed
Enable multi blob/clob insertion tests
1 parent 0857d68 commit cbed304

File tree

3 files changed

+256
-1
lines changed

3 files changed

+256
-1
lines changed

test/list.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -781,4 +781,9 @@ Overview of node-oracledb functional tests
781781
66.1 allows overwriting of public methods on pool instances
782782
66.2 allows overwriting of public methods on connection instances
783783
66.3 allows overwriting of public methods on resultset instances
784-
66.4 allows overwriting of public methods on lob instances
784+
66.4 allows overwriting of public methods on lob instances
785+
786+
787+
68. multipleLobInsertion.js
788+
68.1 inserts multiple BLOBs
789+
68.2 inserts multiple CLOBs

test/multipleLobInsertion.js

Lines changed: 249 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
/* Copyright (c) 2015, 2016, 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+
* The node-oracledb test suite uses 'mocha', 'should' and 'async'.
19+
* See LICENSE.md for relevant licenses.
20+
*
21+
* NAME
22+
* 68. multipleLobInsertion.js
23+
*
24+
* DESCRIPTION
25+
* Testing external authentication functionality.
26+
*
27+
* Note that enabling the externalAuth feature requires configuration on the
28+
* database besides setting "externalAuth" attribute to be true. Please refer
29+
* to api doc about the configuration.
30+
* https://github.com/oracle/node-oracledb/blob/master/doc/api.md#extauth
31+
*
32+
* NUMBERING RULE
33+
* Test numbers follow this numbering rule:
34+
* 1 - 20 are reserved for basic functional tests
35+
* 21 - 50 are reserved for data type supporting tests
36+
* 51 onwards are for other tests
37+
*
38+
*****************************************************************************/
39+
'use strict';
40+
41+
var oracledb = require('oracledb');
42+
var should = require('should');
43+
var async = require('async');
44+
var fs = require('fs');
45+
var dbConfig = require('./dbconfig.js');
46+
47+
describe('68. multipleLobInsertion.js', function() {
48+
49+
var connection = null;
50+
before(function(done) {
51+
52+
async.series([
53+
function getConn(cb) {
54+
oracledb.getConnection(
55+
dbConfig,
56+
function(err, conn) {
57+
should.not.exist(err);
58+
connection = conn;
59+
cb();
60+
}
61+
);
62+
},
63+
function createTabBLOB(cb) {
64+
var proc = "BEGIN \n" +
65+
" DECLARE \n" +
66+
" e_table_missing EXCEPTION; \n" +
67+
" PRAGMA EXCEPTION_INIT(e_table_missing, -00942); \n" +
68+
" BEGIN \n" +
69+
" EXECUTE IMMEDIATE('DROP TABLE nodb_multi_blob'); \n" +
70+
" EXCEPTION \n" +
71+
" WHEN e_table_missing \n" +
72+
" THEN NULL; \n" +
73+
" END; \n" +
74+
" EXECUTE IMMEDIATE (' \n" +
75+
" CREATE TABLE nodb_multi_blob ( \n" +
76+
" id NUMBER, \n" +
77+
" b1 BLOB, \n" +
78+
" b2 BLOB, \n" +
79+
" b3 BLOB, \n" +
80+
" b4 BLOB, \n" +
81+
" b5 BLOB \n" +
82+
" ) \n" +
83+
" '); \n" +
84+
"END; ";
85+
86+
connection.execute(
87+
proc,
88+
function(err) {
89+
should.not.exist(err);
90+
cb();
91+
}
92+
);
93+
},
94+
function createTabCLOB(cb) {
95+
var proc = "BEGIN \n" +
96+
" DECLARE \n" +
97+
" e_table_missing EXCEPTION; \n" +
98+
" PRAGMA EXCEPTION_INIT(e_table_missing, -00942); \n" +
99+
" BEGIN \n" +
100+
" EXECUTE IMMEDIATE('DROP TABLE nodb_multi_clob'); \n" +
101+
" EXCEPTION \n" +
102+
" WHEN e_table_missing \n" +
103+
" THEN NULL; \n" +
104+
" END; \n" +
105+
" EXECUTE IMMEDIATE (' \n" +
106+
" CREATE TABLE nodb_multi_clob ( \n" +
107+
" id NUMBER, \n" +
108+
" c1 CLOB, \n" +
109+
" c2 CLOB, \n" +
110+
" c3 CLOB, \n" +
111+
" c4 CLOB, \n" +
112+
" c5 CLOB \n" +
113+
" ) \n" +
114+
" '); \n" +
115+
"END; ";
116+
117+
connection.execute(
118+
proc,
119+
function(err) {
120+
should.not.exist(err);
121+
cb();
122+
}
123+
);
124+
}
125+
], done);
126+
127+
}); // before
128+
129+
after(function(done) {
130+
async.series([
131+
function(cb) {
132+
connection.execute(
133+
"DROP TABLE nodb_multi_clob",
134+
function(err) {
135+
should.not.exist(err);
136+
cb();
137+
}
138+
);
139+
},
140+
function(cb) {
141+
connection.execute(
142+
"DROP TABLE nodb_multi_blob",
143+
function(err) {
144+
should.not.exist(err);
145+
cb();
146+
}
147+
);
148+
},
149+
function(cb) {
150+
connection.release(function(err) {
151+
should.not.exist(err);
152+
cb();
153+
});
154+
}
155+
], done);
156+
}); // after
157+
158+
var lobInsert = function(sql, bindv, inFileName, cb) {
159+
160+
connection.execute(
161+
sql,
162+
bindv,
163+
{ autoCommit: false },
164+
function(err, result) {
165+
should.not.exist(err);
166+
167+
var lobArr = new Array();
168+
169+
// put lobbv1..5 to lobArr
170+
for(var item in result.outBinds) {
171+
lobArr.push(result.outBinds[item][0]);
172+
}
173+
174+
async.eachSeries(
175+
lobArr,
176+
function(lob, callback) {
177+
var inStream = fs.createReadStream(inFileName);
178+
179+
inStream.pipe(lob);
180+
181+
// one task completes
182+
lob.on('finish', function() {
183+
return callback();
184+
});
185+
186+
lob.on('error', function(err) {
187+
return callback(err);
188+
});
189+
190+
inStream.on('error', function(err) {
191+
return callback(err);
192+
});
193+
},
194+
function(err) {
195+
should.not.exist(err);
196+
197+
connection.commit(function(err) {
198+
should.not.exist(err);
199+
return cb();
200+
});
201+
}
202+
); // async.eachSeries
203+
204+
}
205+
);
206+
207+
};
208+
209+
it('68.1 inserts multiple BLOBs', function(done) {
210+
211+
var sql = "insert into nodb_multi_blob values(1, " +
212+
" EMPTY_BLOB(), EMPTY_BLOB(), EMPTY_BLOB(), EMPTY_BLOB(), EMPTY_BLOB() ) " +
213+
" returning b1, b2, b3, b4, b5 into :lobbv1, :lobbv2, :lobbv3, :lobbv4, :lobbv5";
214+
215+
var bindvars = {
216+
lobbv1: { type: oracledb.BLOB, dir: oracledb.BIND_OUT },
217+
lobbv2: { type: oracledb.BLOB, dir: oracledb.BIND_OUT },
218+
lobbv3: { type: oracledb.BLOB, dir: oracledb.BIND_OUT },
219+
lobbv4: { type: oracledb.BLOB, dir: oracledb.BIND_OUT },
220+
lobbv5: { type: oracledb.BLOB, dir: oracledb.BIND_OUT }
221+
};
222+
223+
var inFileName = './test/fuzzydinosaur.jpg';
224+
225+
lobInsert(sql, bindvars, inFileName, done);
226+
227+
}); // 68.1
228+
229+
it('68.2 inserts multiple CLOBs', function(done) {
230+
231+
var sql = "insert into nodb_multi_clob values(1, " +
232+
" EMPTY_CLOB(), EMPTY_CLOB(), EMPTY_CLOB(), EMPTY_CLOB(), EMPTY_CLOB() ) " +
233+
" returning c1, c2, c3, c4, c5 into :lobbv1, :lobbv2, :lobbv3, :lobbv4, :lobbv5";
234+
235+
var bindvars = {
236+
lobbv1: { type: oracledb.CLOB, dir: oracledb.BIND_OUT },
237+
lobbv2: { type: oracledb.CLOB, dir: oracledb.BIND_OUT },
238+
lobbv3: { type: oracledb.CLOB, dir: oracledb.BIND_OUT },
239+
lobbv4: { type: oracledb.CLOB, dir: oracledb.BIND_OUT },
240+
lobbv5: { type: oracledb.CLOB, dir: oracledb.BIND_OUT }
241+
};
242+
243+
var inFileName = './test/clobexample.txt';
244+
245+
lobInsert(sql, bindvars, inFileName, done);
246+
247+
});
248+
249+
});

test/opts/mocha.opts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,4 @@ test/autoCommit4nestedExecutes.js
6868
test/sqlWithWarnings.js
6969
test/uninitializedLob.js
7070
test/writableProperties.js
71+
test/multipleLobInsertion.js

0 commit comments

Comments
 (0)