Skip to content

Commit 24496e1

Browse files
committed
Add some new CLOB tests
1 parent b5ee82f commit 24496e1

File tree

3 files changed

+132
-72
lines changed

3 files changed

+132
-72
lines changed

test/clobPlsqlString.js

Lines changed: 126 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
* PL/SQL OUT CLOB parameters can also be bound as `STRING`
2727
* The returned length is limited to the maximum size of maxSize option.
2828
*
29+
* When the types of bind out variables are not STRING or BUFFER,
30+
* maxSize option will not take effect.
31+
*
2932
* NUMBERING RULE
3033
* Test numbers follow this numbering rule:
3134
* 1 - 20 are reserved for basic functional tests
@@ -38,6 +41,7 @@
3841
var oracledb = require('oracledb');
3942
var async = require('async');
4043
var should = require('should');
44+
var stream = require('stream');
4145
var dbConfig = require('./dbConfig.js');
4246
var assist = require('./dataTypeAssist.js');
4347

@@ -51,35 +55,25 @@ describe('60. clobPlsqlString.js', function() {
5155

5256
var connection = null;
5357
var tableName = "oracledb_myclobs";
54-
58+
5559
before('get one connection, prepare table', function(done) {
5660
async.series([
5761
function(callback) {
5862
oracledb.getConnection(
59-
credential,
63+
credential,
6064
function(err, conn) {
61-
should.not.exist(err);
62-
connection = conn;
63-
callback();
65+
should.not.exist(err);
66+
connection = conn;
67+
callback();
6468
}
6569
);
6670
},
6771
function(callback) {
6872
assist.createTable(connection, tableName, callback);
69-
},
70-
function(callback) {
71-
connection.execute(
72-
"INSERT INTO oracledb_myclobs (num, content) VALUES (1, 'abcdefghijklmnopqrstuvwxyz')",
73-
function(err) {
74-
should.not.exist(err);
75-
callback();
76-
}
77-
);
7873
}
7974
], done);
75+
}) // before
8076

81-
})
82-
8377
after('release connection', function(done) {
8478
async.series([
8579
function(callback) {
@@ -98,37 +92,122 @@ describe('60. clobPlsqlString.js', function() {
9892
});
9993
}
10094
], done);
95+
}) // after
10196

102-
})
97+
describe('60.1 BIND OUT as STRING', function() {
98+
before('insert data', function(done) {
99+
connection.execute(
100+
"INSERT INTO oracledb_myclobs (num, content) VALUES (1, 'abcdefghijklmnopqrstuvwxyz')",
101+
function(err) {
102+
should.not.exist(err);
103+
done();
104+
}
105+
);
106+
}) // before
107+
108+
it('60.1.1 PL/SQL OUT CLOB parameters can also be bound as STRING', function(done) {
109+
connection.execute(
110+
"BEGIN SELECT content INTO :cbv FROM oracledb_myclobs WHERE num = :id; END;",
111+
{
112+
id: 1,
113+
cbv: { type: oracledb.STRING, dir: oracledb.BIND_OUT}
114+
},
115+
function(err, result) {
116+
should.not.exist(err);
117+
(result.outBinds.cbv).should.be.a.String;
118+
(result.outBinds.cbv).should.eql('abcdefghijklmnopqrstuvwxyz');
119+
done();
120+
}
121+
);
122+
}) // 60.1.1
103123

104-
it('60.1 PL/SQL OUT CLOB parameters can also be bound as STRING', function(done) {
105-
connection.execute(
106-
"BEGIN SELECT content INTO :cbv FROM oracledb_myclobs WHERE num = :id; END;",
107-
{
108-
id: 1,
109-
cbv: { type: oracledb.STRING, dir: oracledb.BIND_OUT}
110-
},
111-
function(err, result) {
112-
should.not.exist(err);
113-
(result.outBinds.cbv).should.be.a.String;
114-
(result.outBinds.cbv).should.eql('abcdefghijklmnopqrstuvwxyz');
115-
done();
116-
}
117-
);
118-
})
119-
120-
it('60.2 The returned length is limited to the maximum size', function(done) {
121-
connection.execute(
122-
"BEGIN SELECT content INTO :cbv FROM oracledb_myclobs WHERE num = :id; END;",
123-
{
124-
id: 1,
125-
cbv: { type: oracledb.STRING, dir: oracledb.BIND_OUT, maxSize: 5 }
126-
},
127-
function(err, result) {
128-
should.exist(err);
129-
(err.message).should.startWith('ORA-06502'); // PL/SQL: numeric or value error
130-
done();
131-
}
132-
);
133-
})
124+
it('60.1.2 The returned length is limited to the maximum size', function(done) {
125+
connection.execute(
126+
"BEGIN SELECT content INTO :cbv FROM oracledb_myclobs WHERE num = :id; END;",
127+
{
128+
id: 1,
129+
cbv: { type: oracledb.STRING, dir: oracledb.BIND_OUT, maxSize: 5 }
130+
},
131+
function(err, result) {
132+
should.exist(err);
133+
(err.message).should.startWith('ORA-06502'); // PL/SQL: numeric or value error
134+
done();
135+
}
136+
);
137+
}) // 60.1.2
138+
}) // 60.1
139+
140+
describe('60.2 BIND OUT as CLOB', function() {
141+
var dataLength = 1000000;
142+
var rawData = assist.createCharString(dataLength);
143+
144+
it('60.2.1 maxSize option does not take effect when bind out type is clob', function(done) {
145+
async.series([
146+
function doInsert(callback) {
147+
connection.execute(
148+
"INSERT INTO " + tableName + " VALUES (2, EMPTY_CLOB()) RETURNING content INTO :lobbv",
149+
{ lobbv: {type: oracledb.CLOB, dir: oracledb.BIND_OUT} },
150+
{ autoCommit: false },
151+
function(err, result) {
152+
should.not.exist(err);
153+
154+
var lob = result.outBinds.lobbv[0];
155+
lob.on('error', function(err) {
156+
should.not.exist(err);
157+
return callback(err);
158+
});
159+
160+
var inStream = new stream.Readable();
161+
inStream._read = function noop() {};
162+
inStream.push(rawData);
163+
inStream.push(null);
164+
165+
inStream.on('error', function(err) {
166+
should.not.exist(err);
167+
return callback(err);
168+
});
169+
170+
inStream.on('end', function() {
171+
connection.commit(function(err) {
172+
should.not.exist(err);
173+
callback();
174+
});
175+
});
176+
177+
inStream.pipe(lob);
178+
}
179+
);
180+
},
181+
function doQuery(callback) {
182+
connection.execute(
183+
"BEGIN SELECT content INTO :bv FROM " + tableName + " WHERE num = 2; END;",
184+
{ bv: {dir: oracledb.BIND_OUT, type: oracledb.CLOB} },
185+
{ maxRows: 500 },
186+
function(err, result) {
187+
should.not.exist(err);
188+
189+
var content = '';
190+
var lob = result.outBinds.bv;
191+
lob.setEncoding('utf8');
192+
193+
lob.on('data', function(chunk) {
194+
content += chunk;
195+
});
196+
197+
lob.on('end', function() {
198+
(content.length).should.be.exactly(dataLength);
199+
(content).should.eql(rawData);
200+
callback();
201+
});
202+
203+
lob.on('error', function(err) {
204+
should.not.exist(err);
205+
});
206+
}
207+
);
208+
}
209+
], done);
210+
})
211+
}) // 60.2
212+
134213
})

test/dataTypeRaw.js

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,10 @@ describe('42. dataTypeRaw.js', function() {
164164
);
165165
})
166166

167-
it('42.3.1 INSERT statement with Object binding', function(done) {
167+
it.only('42.3.1 INSERT statement with Object binding', function(done) {
168168
var seq = 1;
169169
var size = 10;
170170
var bindValue = assist.createBuffer(size);
171-
// console.log("original value", bindValue.toString('hex'));
172171

173172
connection.execute(
174173
"INSERT INTO " + tableName + " VALUES (:n, :c) RETURNING num, content INTO :rid, :rc",
@@ -183,8 +182,6 @@ describe('42. dataTypeRaw.js', function() {
183182
should.exist(err);
184183
(err.message).should.startWith('NJS-028');
185184
// NJS-028: raw database type is not supported with DML Returning statements
186-
// (result.outBinds.rc[0].toString('hex')).should.eql(bindValue.toString('hex'));
187-
// (result.outBinds.rc[0].length).should.be.exactly(size);
188185
done();
189186
}
190187
);
@@ -207,10 +204,6 @@ describe('42. dataTypeRaw.js', function() {
207204
function(err, result) {
208205
should.exist(err);
209206
(err.message).should.startWith('NJS-028');
210-
// console.log(result);
211-
// (result.outBinds.rc[0].toString('hex')).should.eql(bindValue.toString('hex'));
212-
// (result.outBinds.rc[0].length).should.be.exactly(size);
213-
done();
214207
}
215208
);
216209
}) // 42.3.2
@@ -232,9 +225,6 @@ describe('42. dataTypeRaw.js', function() {
232225
function(err, result) {
233226
should.exist(err);
234227
(err.message).should.startWith('NJS-028');
235-
// console.log(result);
236-
// (result.outBinds.rc[0].toString('hex')).should.eql(bindValue.toString('hex'));
237-
// (result.outBinds.rc[0].length).should.be.exactly(size);
238228
done();
239229
}
240230
);
@@ -246,7 +236,6 @@ describe('42. dataTypeRaw.js', function() {
246236
var bindValue = assist.createBuffer(size);
247237

248238
connection.execute(
249-
//"INSERT INTO " + tableName + " VALUES (:n, :c) RETURNING num, content INTO :rid, :rc",
250239
"UPDATE " + tableName + " SET content = :c WHERE num = :n RETURNING num, content INTO :rid, :rc",
251240
{
252241
n : seq,
@@ -258,9 +247,6 @@ describe('42. dataTypeRaw.js', function() {
258247
function(err, result) {
259248
should.exist(err);
260249
(err.message).should.startWith('NJS-028');
261-
// console.log(result);
262-
// (result.outBinds.rc[0].toString('hex')).should.eql(bindValue.toString('hex'));
263-
// (result.outBinds.rc[0].length).should.be.exactly(size);
264250
done();
265251
}
266252
);
@@ -270,7 +256,6 @@ describe('42. dataTypeRaw.js', function() {
270256
var seq = 1;
271257

272258
connection.execute(
273-
// "INSERT INTO " + tableName + " VALUES (:n, :c) RETURNING num, content INTO :rid, :rc",
274259
"DELETE FROM " + tableName + " WHERE num = :1 RETURNING num, content INTO :2, :3",
275260
[
276261
seq,
@@ -281,9 +266,6 @@ describe('42. dataTypeRaw.js', function() {
281266
function(err, result) {
282267
should.exist(err);
283268
(err.message).should.startWith('NJS-028');
284-
// console.log(result);
285-
// (result.outBinds.rc[0].toString('hex')).should.eql(bindValue.toString('hex'));
286-
// (result.outBinds.rc[0].length).should.be.exactly(size);
287269
done();
288270
}
289271
);
@@ -293,7 +275,6 @@ describe('42. dataTypeRaw.js', function() {
293275
var seq = 1;
294276

295277
connection.execute(
296-
// "INSERT INTO " + tableName + " VALUES (:n, :c) RETURNING num, content INTO :rid, :rc",
297278
"DELETE FROM " + tableName + " WHERE num > :n RETURNING num, content INTO :rid, :rc",
298279
{
299280
n : seq,
@@ -304,9 +285,6 @@ describe('42. dataTypeRaw.js', function() {
304285
function(err, result) {
305286
should.exist(err);
306287
(err.message).should.startWith('NJS-028');
307-
// console.log(result);
308-
// (result.outBinds.rc[0].toString('hex')).should.eql(bindValue.toString('hex'));
309-
// (result.outBinds.rc[0].length).should.be.exactly(size);
310288
done();
311289
}
312290
);

test/list.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -496,8 +496,11 @@
496496
59.1.1 reads clob data one by one row from result set
497497

498498
60. clobPlsqlString.js
499-
60.1 PL/SQL OUT CLOB parameters can also be bound as STRING
500-
60.2 The returned length is limited to the maximum size
499+
60.1 BIND OUT as STRING
500+
60.1.1 PL/SQL OUT CLOB parameters can also be bound as STRING
501+
60.1.2 The returned length is limited to the maximum size
502+
60.2 BIND OUT as CLOB
503+
60.2.1 maxSize option does not take effect when bind out type is clob
501504

502505
61. checkClassesTypes.js
503506
61.1 Oracledb class

0 commit comments

Comments
 (0)