Skip to content

Commit 61bcfde

Browse files
committed
Test updates and fix some line endings
1 parent 044e63e commit 61bcfde

File tree

5 files changed

+602
-382
lines changed

5 files changed

+602
-382
lines changed

test/dataTypeRaw.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,20 @@ describe('42. dataTypeRaw.js', function() {
125125
}
126126
});
127127
}
128-
})
128+
}) // 42.1.4
129+
130+
it('42.1.5 a negative case which hits NJS-011 error', function(done) {
131+
connection.execute(
132+
"INSERT INTO " + tableName + " (content ) VALUES (:c)",
133+
{ c : { val: 1234, type: oracledb.BUFFER, dir:oracledb.BIND_IN } },
134+
function(err, result) {
135+
should.exist(err);
136+
// NJS-011: encountered bind value and type mismatch
137+
(err.message).should.startWith('NJS-011:');
138+
done();
139+
}
140+
);
141+
})
129142

130143
})
131144

@@ -324,22 +337,27 @@ describe('42. dataTypeRaw.js', function() {
324337
);
325338
})
326339

327-
it('42.4.1 value with the maximum size', function(done) {
328-
var buf = assist.createBuffer(5000);
340+
it('42.4.1 when data length is 200', function(done) {
341+
var buf = assist.createBuffer(2);
329342

330343
connection.execute(
331344
"BEGIN oracledb_testraw(:i, :o); END;",
332345
{
333346
i: { type: oracledb.BUFFER, dir: oracledb.BIND_IN, val: buf },
334-
o: { type: oracledb.STRING, dir: oracledb.BIND_OUT, maxSize: 32767 }
347+
o: { type: oracledb.BUFFER, dir: oracledb.BIND_OUT, maxSize: 20}
335348
},
349+
/* ORA-06502: PL/SQL: numeric or value error: raw variable length too long */
336350
function(err, result) {
337351
should.not.exist(err);
338352
// console.log(result);
353+
//(result.outBinds.o.length).should.be.exactly(200);
354+
// console.log(result.outBinds.o.length);
355+
console.log( Buffer.isBuffer(result.outBinds.o) );
339356
done();
340357
}
341358
);
342359
})
343360

344361
}) // 42.4
362+
345363
})

test/externalAuthentication.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ describe('5. externalAuthentication.js', function(){
115115
}
116116
);
117117
} else {
118-
console.log("External Authentication Off.");
118+
// console.log("External Authentication Off.");
119119
done();
120120
}
121121
})
@@ -152,7 +152,7 @@ describe('5. externalAuthentication.js', function(){
152152
}
153153
);
154154
} else {
155-
console.log("External Authentication off.");
155+
// console.log("External Authentication off.");
156156
done();
157157
}
158158
})

test/list.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,25 @@
370370
41.2 stores null value correctly
371371
41.2.1 testing Null, Empty string and Undefined
372372

373+
42. dataTypeRaw.js
374+
42.1 testing RAW data in various lengths
375+
42.1.1 SELECT query
376+
42.1.2 resultSet stores RAW data correctly
377+
42.1.3 works well with REF Cursor
378+
42.1.4 result set getRow() function works well with RAW
379+
42.1.5 a negative case which hits NJS-011 error
380+
42.2 stores null value correctly
381+
42.2.1 testing Null, Empty string and Undefined
382+
42.3 DML Returning
383+
42.3.1 INSERT statement with Object binding
384+
42.3.2 INSERT statement with ARRAY binding
385+
42.3.3 INSERT statement with exact maxSize restriction
386+
42.3.4 UPDATE statement
387+
42.3.6 DELETE statement with single row matching
388+
42.3.7 DELETE statement with multiple rows matching
389+
42.4 in PL/SQL, the maximum size is 32767
390+
- 42.4.1 when data length is 200
391+
373392
51. accessTerminatedPoolAttributes.js
374393
can not access attributes of terminated pool
375394

@@ -454,3 +473,7 @@
454473
58.3.3 clientId
455474
58.3.4 action
456475
58.3.5 module
476+
477+
59. lob.js
478+
59.1 CLOB data
479+
59.1.1 reads clob data one by one row from result set

test/lob.js

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
/* Copyright (c) 2015, 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+
* 59. lob.js
23+
*
24+
* DESCRIPTION
25+
*
26+
* Testing Lob data and result set.
27+
* Create a table contains Lob data. Read the Lob to result set. Get
28+
* rows one by one. Read the lob data on each row.
29+
*
30+
* NUMBERING RULE
31+
* Test numbers follow this numbering rule:
32+
* 1 - 20 are reserved for basic functional tests
33+
* 21 - 50 are reserved for data type supporting tests
34+
* 51 onwards are for other tests
35+
*
36+
*****************************************************************************/
37+
"use strict";
38+
39+
var oracledb = require('oracledb');
40+
var fs = require('fs');
41+
var async = require('async');
42+
var should = require('should');
43+
var stream = require('stream');
44+
var dbConfig = require('./dbConfig.js');
45+
var assist = require('./dataTypeAssist.js');
46+
47+
var inFileName = './test/clobexample.txt';
48+
49+
describe('59. lob.js', function() {
50+
51+
if(dbConfig.externalAuth){
52+
var credential = { externalAuth: true, connectString: dbConfig.connectString };
53+
} else {
54+
var credential = dbConfig;
55+
}
56+
57+
var connection = null;
58+
before('get one connection', function(done) {
59+
oracledb.getConnection(credential, function(err, conn) {
60+
should.not.exist(err);
61+
connection = conn;
62+
done();
63+
});
64+
})
65+
66+
after('release connection', function(done) {
67+
connection.release( function(err) {
68+
should.not.exist(err);
69+
done();
70+
});
71+
})
72+
73+
describe('59.1 CLOB data', function() {
74+
75+
var tableName = "oracledb_myclobs";
76+
before('create table', function(done) {
77+
assist.createTable(connection, tableName, done);
78+
})
79+
80+
after(function(done) {
81+
connection.execute(
82+
"DROP table " + tableName,
83+
function(err) {
84+
should.not.exist(err);
85+
done();
86+
}
87+
);
88+
})
89+
90+
it('59.1.1 reads clob data one by one row from result set', function(done) {
91+
async.series([
92+
function(callback) {
93+
insertClob(1, callback);
94+
},
95+
function(callback) {
96+
insertClob(2, callback);
97+
},
98+
function(callback) {
99+
insertClob(3, callback);
100+
},
101+
function(callback) {
102+
connection.execute(
103+
"SELECT num, content FROM " + tableName,
104+
[],
105+
{ resultSet: true },
106+
function(err, result) {
107+
should.not.exist(err);
108+
// console.log(result);
109+
fetchOneRowFromRS(result.resultSet, callback);
110+
}
111+
);
112+
}
113+
], done);
114+
})
115+
116+
function fetchOneRowFromRS(resultSet, callback)
117+
{
118+
resultSet.getRow( function(err, row) {
119+
should.not.exist(err);
120+
if (!row) {
121+
resultSet.close( function(err) {
122+
should.not.exist(err);
123+
callback();
124+
});
125+
}
126+
else {
127+
var lob = row[1];
128+
lob.setEncoding('utf8');
129+
130+
var text = '';
131+
lob.on('data', function(chunk) {
132+
text += chunk;
133+
});
134+
135+
lob.on('end', function() {
136+
fetchOneRowFromRS(resultSet, callback);
137+
});
138+
139+
lob.on('error', function(err) {
140+
console.log("lob.on 'error' event");
141+
console.error(err.message);
142+
});
143+
}
144+
145+
});
146+
}
147+
148+
function insertClob(id, cb)
149+
{
150+
connection.execute(
151+
"INSERT INTO " + tableName + " VALUES (:n, EMPTY_CLOB()) RETURNING content INTO :lobbv",
152+
{ n: id, lobbv: { type: oracledb.CLOB, dir: oracledb.BIND_OUT } },
153+
function(err, result) {
154+
should.not.exist(err);
155+
var lob = result.outBinds.lobbv[0];
156+
var inStream = fs.createReadStream(inFileName);
157+
158+
inStream.pipe(lob);
159+
160+
inStream.on('end', function() {
161+
connection.commit( function(err) {
162+
should.not.exist(err);
163+
cb(); // insertion done
164+
});
165+
});
166+
167+
inStream.on('error', function(err) {
168+
should.not.exist(err);
169+
});
170+
171+
}
172+
);
173+
}
174+
175+
}) // 59.1
176+
177+
}) // 59
178+

0 commit comments

Comments
 (0)