Skip to content

Commit 4d0f040

Browse files
committed
Improve RAW code and add tests
1 parent 5f62168 commit 4d0f040

File tree

3 files changed

+77
-12
lines changed

3 files changed

+77
-12
lines changed

src/njs/src/njsConnection.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3133,7 +3133,16 @@ void Connection::cbDynBufferAllocate ( void *ctx, bool dmlReturning,
31333133
break;
31343134

31353135
case dpi::DpiRaw:
3136-
bind->value = (void *)malloc ( bind->maxSize ) ;
3136+
if ( NJS_SIZE_T_OVERFLOW ( bind->maxSize, nRows ) )
3137+
{
3138+
executeBaton->error = NJSMessages::getErrorMsg ( errResultsTooLarge );
3139+
return;
3140+
}
3141+
else
3142+
{
3143+
bind->value = (void *)malloc ( (size_t)(bind->maxSize) * nRows ) ;
3144+
*(bind->len) = (unsigned int)bind->maxSize;
3145+
}
31373146
break;
31383147
}
31393148
}

src/njs/src/njsMessages.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ static const char *errMsg[] =
6161
"NJS-025: overflow when calculating results area size",
6262
"NJS-026: maxRows must be greater than zero",
6363
"NJS-027: unexpected SQL parsing error",
64-
"NJS-027: raw database type is not supported with DML Returning statements",
64+
"NJS-028: raw database type is not supported with DML Returning statements",
6565
};
6666

6767
string NJSMessages::getErrorMsg ( NJSErrorType err, ... )

test/dataTypeRaw.js

Lines changed: 66 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ describe('42. dataTypeRaw.js', function() {
308308

309309
}) // 42.3
310310

311-
describe.skip('42.4 in PL/SQL, the maximum size is 32767', function() {
311+
describe('42.4 in PL/SQL, the maximum size is 32767', function() {
312312

313313
var proc =
314314
"CREATE OR REPLACE PROCEDURE oracledb_testraw (p_in IN RAW, p_out OUT RAW) " +
@@ -337,27 +337,83 @@ describe('42. dataTypeRaw.js', function() {
337337
);
338338
})
339339

340-
it('42.4.1 when data length is 200', function(done) {
341-
var buf = assist.createBuffer(2);
340+
it('42.4.1 when data length is less than maxSize', function(done) {
341+
var size = 5;
342+
var buf = assist.createBuffer(size);
342343

343344
connection.execute(
344345
"BEGIN oracledb_testraw(:i, :o); END;",
345346
{
346347
i: { type: oracledb.BUFFER, dir: oracledb.BIND_IN, val: buf },
347-
o: { type: oracledb.BUFFER, dir: oracledb.BIND_OUT, maxSize: 20}
348+
o: { type: oracledb.BUFFER, dir: oracledb.BIND_OUT, maxSize: 10}
348349
},
349-
/* ORA-06502: PL/SQL: numeric or value error: raw variable length too long */
350350
function(err, result) {
351351
should.not.exist(err);
352-
// 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) );
352+
353+
( Buffer.isBuffer(result.outBinds.o) ).should.equal(true, "Error: the bind out data is not a Buffer");
354+
(result.outBinds.o.length).should.be.exactly(size);
356355
done();
357356
}
358357
);
359358
})
360359

360+
it('42.4.2 when data length is 32767', function(done) {
361+
var size = 32767;
362+
var buf = assist.createBuffer(size);
363+
364+
connection.execute(
365+
"BEGIN oracledb_testraw(:i, :o); END;",
366+
{
367+
i: { type: oracledb.BUFFER, dir: oracledb.BIND_IN, val: buf },
368+
o: { type: oracledb.BUFFER, dir: oracledb.BIND_OUT, maxSize: 32767}
369+
},
370+
function(err, result) {
371+
should.not.exist(err);
372+
373+
( Buffer.isBuffer(result.outBinds.o) ).should.equal(true, "Error: the bind out data is not a Buffer");
374+
(result.outBinds.o.length).should.be.exactly(size);
375+
done();
376+
}
377+
);
378+
})
379+
380+
it('42.4.3 when data length greater than maxSize', function(done) {
381+
var size = 32800;
382+
var buf = assist.createBuffer(size);
383+
384+
connection.execute(
385+
"BEGIN oracledb_testraw(:i, :o); END;",
386+
{
387+
i: { type: oracledb.BUFFER, dir: oracledb.BIND_IN, val: buf },
388+
o: { type: oracledb.BUFFER, dir: oracledb.BIND_OUT, maxSize: 32767}
389+
},
390+
function(err, result) {
391+
should.exist(err);
392+
// ORA-01460: unimplemented or unreasonable conversion requested
393+
(err.message).should.startWith('ORA-01460');
394+
done();
395+
}
396+
);
397+
})
398+
399+
it('42.4.4 when maxSize is greater than 32767', function(done) {
400+
var size = 32800;
401+
var buf = assist.createBuffer(size);
402+
403+
connection.execute(
404+
"BEGIN oracledb_testraw(:i, :o); END;",
405+
{
406+
i: { type: oracledb.BUFFER, dir: oracledb.BIND_IN, val: buf },
407+
o: { type: oracledb.BUFFER, dir: oracledb.BIND_OUT, maxSize: 40000}
408+
},
409+
function(err, result) {
410+
should.exist(err);
411+
// ORA-01460: unimplemented or unreasonable conversion requested
412+
(err.message).should.startWith('ORA-01460');
413+
done();
414+
}
415+
);
416+
})
361417
}) // 42.4
362418

363-
})
419+
})

0 commit comments

Comments
 (0)