Skip to content

Commit 4dd746b

Browse files
committed
Add 12c row limit SQL case and LOB object test cases
1 parent f5a33a5 commit 4dd746b

File tree

3 files changed

+73
-4
lines changed

3 files changed

+73
-4
lines changed

test/connection.js

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ describe('1. connection.js', function(){
169169
END; \
170170
EXECUTE IMMEDIATE (' \
171171
CREATE TABLE oracledb_employees ( \
172-
employees_id NUMBER, \
173-
employees_name VARCHAR2(20) \
172+
employee_id NUMBER, \
173+
employee_name VARCHAR2(20) \
174174
) \
175175
'); \
176176
END; ";
@@ -286,6 +286,35 @@ describe('1. connection.js', function(){
286286
}
287287
);
288288
})
289+
290+
it('1.2.6 shows 12c new way to limit the number of records fetched by queries', function(done) {
291+
connection.should.be.ok;
292+
293+
var myoffset = 2; // number of rows to skip
294+
var mymaxnumrows = 6; // number of rows to fetch
295+
var sql = "SELECT employee_id, employee_name FROM oracledb_employees ORDER BY employee_id";
296+
297+
if (connection.oracleServerVersion >= 1201000000) {
298+
// 12c row-limiting syntax
299+
sql += " OFFSET :offset ROWS FETCH NEXT :maxnumrows ROWS ONLY";
300+
} else {
301+
// Pre-12c syntax [could also customize the original query and use row_number()]
302+
sql = "SELECT * FROM (SELECT A.*, ROWNUM AS MY_RNUM FROM"
303+
+ "(" + sql + ") A "
304+
+ "WHERE ROWNUM <= :maxnumrows + :offset) WHERE MY_RNUM > :offset";
305+
}
306+
307+
connection.execute(
308+
sql,
309+
{ offset: myoffset, maxnumrows: mymaxnumrows },
310+
{ maxRows: 150 },
311+
function(err, result) {
312+
should.not.exist(err);
313+
(result.rows.length).should.eql(mymaxnumrows);
314+
done();
315+
}
316+
);
317+
})
289318
})
290319

291320
describe('1.3 can call PL/SQL procedures', function(){

test/dataTypeClob.js

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
* clobinsert1.js, clobstream1.js and clobstream2.js
2828
* Firstly, reads text from clobexample.txt and INSERTs it into a CLOB column.
2929
* Secondly, SELECTs a CLOB and pipes it to a file, clobstreamout.txt
30-
* Thirdly, SELECTs the CLOB and compares it with the content in clobexample.txt
30+
* Thirdly, SELECTs the CLOB and compares it with the content in clobexample.txt.
31+
* Fourthly, query the CLOB with Object outFormat.
3132
*
3233
* NUMBERING RULE
3334
* Test numbers follow this numbering rule:
@@ -49,7 +50,7 @@ var inFileName = './test/clobexample.txt'; // the file with text to be inserted
4950
var outFileName = './test/clobstreamout.txt';
5051

5152
describe('40. dataTypeClob.js', function() {
52-
this.timeout(10000);
53+
this.timeout(15000);
5354

5455
if(dbConfig.externalAuth){
5556
var credential = { externalAuth: true, connectString: dbConfig.connectString };
@@ -212,6 +213,43 @@ describe('40. dataTypeClob.js', function() {
212213
});
213214
});
214215

216+
lob.on('error', function(err) {
217+
should.not.exist(err, "lob.on 'error' event");
218+
});
219+
}
220+
);
221+
},
222+
function objectOutFormat(callback) {
223+
var lobEndEventFired = false;
224+
var lobDataEventFired = false;
225+
setTimeout( function(){
226+
lobDataEventFired.should.equal(true, "lob does not call 'data' event!");
227+
lobEndEventFired.should.equal(true, "lob does not call 'end' event!");
228+
callback();
229+
}, 2000);
230+
231+
connection.execute(
232+
"SELECT content FROM oracledb_myclobs WHERE num = :n",
233+
{ n: 1 },
234+
{ outFormat: oracledb.OBJECT },
235+
function(err, result) {
236+
should.not.exist(err);
237+
238+
var clob = '';
239+
var row = result.rows[0];
240+
var lob = row['CONTENT'];
241+
242+
lob.setEncoding('utf8');
243+
244+
lob.on('data', function(chunk) {
245+
lobDataEventFired = true;
246+
clob += chunk;
247+
});
248+
249+
lob.on('end', function() {
250+
lobEndEventFired = true;
251+
});
252+
215253
lob.on('error', function(err) {
216254
should.not.exist(err, "lob.on 'error' event");
217255
});

test/list.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,8 @@
503503
61.1 Oracledb class
504504
61.2 Connection class
505505
61.3 Lob Class
506+
61.4 Pool Class
507+
61.5 ResultSet Class
506508

507509
62. lobProperties.js
508510
62.1 chunkSize (read-only)

0 commit comments

Comments
 (0)