Skip to content

Commit

Permalink
Added support for positional binding of PL/SQL indexed table values
Browse files Browse the repository at this point in the history
  • Loading branch information
Dieter Oberkofler committed Jan 21, 2016
1 parent a7709b9 commit a211c8b
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 11 deletions.
4 changes: 3 additions & 1 deletion src/dpi/include/dpiStmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ class Stmt
// methods
virtual void bind(unsigned int pos, unsigned short type, void *buf,
DPI_SZ_TYPE bufSize, short *ind, DPI_BUFLEN_TYPE *bufLen,
void *data, cbtype cb = NULL ) = 0;
void *data,
unsigned int maxarr_len, unsigned int *curelen,
cbtype cb = NULL ) = 0;

virtual void bind(const unsigned char *name, int nameLen,
unsigned int bndpos,
Expand Down
7 changes: 5 additions & 2 deletions src/dpi/src/dpiStmtImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,9 @@ void StmtImpl::prefetchRows (unsigned int prefetchRows)
*/
void StmtImpl::bind (unsigned int pos, unsigned short type, void *buf,
DPI_SZ_TYPE bufSize, short *ind, DPI_BUFLEN_TYPE *bufLen,
void *data, cbtype cb)
void *data,
unsigned int maxarr_len, unsigned int *curelen,
cbtype cb)
{
OCIBind *b = (OCIBind *)0;

Expand All @@ -256,7 +258,8 @@ void StmtImpl::bind (unsigned int pos, unsigned short type, void *buf,
(type == DpiRSet) ? 0 : bufSize, type,
(cb ? NULL : ind),
(cb ? NULL : bufLen),
NULL, 0, NULL,
NULL,
maxarr_len, curelen,
(cb) ? OCI_DATA_AT_EXEC : OCI_DEFAULT),
errh_);

Expand Down
4 changes: 3 additions & 1 deletion src/dpi/src/dpiStmtImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ class StmtImpl : public Stmt

virtual void bind (unsigned int pos, unsigned short type, void *buf,
DPI_SZ_TYPE bufSize, short *ind, DPI_BUFLEN_TYPE *bufLen,
void *data, cbtype cb);
void *data,
unsigned int maxarr_len, unsigned int *curelen,
cbtype cb);

virtual void bind (const unsigned char *name, int nameLen,
unsigned int bndpos,
Expand Down
4 changes: 3 additions & 1 deletion src/njs/src/njsConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1832,10 +1832,12 @@ void Connection::PrepareAndBind (eBaton* executeBaton)
(executeBaton->binds[index]->maxSize + 1) :
executeBaton->binds[index]->maxSize,
executeBaton->binds[index]->ind,
executeBaton->binds[index]->len,
(executeBaton->binds[index]->isArray) ? executeBaton->binds[index]->len2 : executeBaton->binds[index]->len,
(executeBaton->stmtIsReturning &&
executeBaton->binds[index]->isOut ) ?
(void *)executeBaton : NULL,
(executeBaton->binds[index]->isArray) ? executeBaton->binds[index]->maxArraySize : 0,
(executeBaton->binds[index]->isArray) ? &(executeBaton->binds[index]->curArraySize) : 0,
(executeBaton->stmtIsReturning &&
executeBaton->binds[index]->isOut) ?
Connection::cbDynBufferGet : NULL);
Expand Down
82 changes: 76 additions & 6 deletions test/PLSQLbinds.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('43. PL/SQL binds', function() {
});
})

it('43.1.1 binding PL/SQL indexed table IN', function(done) {
it('43.1.1 binding PL/SQL indexed table IN by name', function(done) {
async.series([
function(callback) {
var proc = "CREATE OR REPLACE PACKAGE\n" +
Expand Down Expand Up @@ -77,9 +77,9 @@ describe('43. PL/SQL binds', function() {
},
function(callback) {
var bindvars = {
result: {type: oracledb.STRING, dir: oracledb.BIND_OUT, maxSize: 2000},
strings: {type: oracledb.STRING, dir: oracledb.BIND_IN, val: [null, 'John', 'Doe']},
numbers: {type: oracledb.NUMBER, dir: oracledb.BIND_IN, val: [null, 8, 11]}
numbers: {type: oracledb.NUMBER, dir: oracledb.BIND_IN, val: [null, 8, 11]},
result: {type: oracledb.STRING, dir: oracledb.BIND_OUT, maxSize: 2000}
};
connection.execute(
"BEGIN :result := oracledb_testpack.test(:strings, :numbers); END;",
Expand All @@ -104,7 +104,77 @@ describe('43. PL/SQL binds', function() {
], done);
});

it('43.1.2 binding PL/SQL indexed table IN OUT', function(done) {
it('43.1.2 binding PL/SQL indexed table IN by position', function(done) {
async.series([
function(callback) {
var proc = "CREATE OR REPLACE PACKAGE\n" +
"oracledb_testpack\n" +
"IS\n" +
" TYPE stringsType IS TABLE OF VARCHAR2(30) INDEX BY BINARY_INTEGER;\n" +
" TYPE numbersType IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;\n" +
" PROCEDURE test(s IN stringsType, n IN numbersType);\n" +
"END;";
connection.should.be.ok;
connection.execute(
proc,
function(err) {
should.not.exist(err);
callback();
}
);
},
function(callback) {
var proc = "CREATE OR REPLACE PACKAGE BODY\n" +
"oracledb_testpack\n" +
"IS\n" +
" PROCEDURE test(s IN stringsType, n IN numbersType)\n" +
" IS\n" +
" BEGIN\n" +
" IF (s(1) IS NULL OR s(1) <> 'John') THEN\n" +
" raise_application_error(-20000, 'Invalid s(1): \"' || s(1) || '\"');\n" +
" END IF;\n" +
" IF (s(2) IS NULL OR s(2) <> 'Doe') THEN\n" +
" raise_application_error(-20000, 'Invalid s(2): \"' || s(2) || '\"');\n" +
" END IF;\n" +
" END;\n" +
"END;";
connection.should.be.ok;
connection.execute(
proc,
function(err) {
should.not.exist(err);
callback();
}
);
},
function(callback) {
var bindvars = [
{type: oracledb.STRING, dir: oracledb.BIND_IN, val: ['John', 'Doe']},
{type: oracledb.NUMBER, dir: oracledb.BIND_IN, val: [8, 11]}
];
connection.execute(
"BEGIN oracledb_testpack.test(:1, :2); END;",
bindvars,
function(err, result) {
should.not.exist(err);
// console.log(result);
callback();
}
);
},
function(callback) {
connection.execute(
"DROP PACKAGE oracledb_testpack",
function(err) {
should.not.exist(err);
callback();
}
);
}
], done);
});

it('43.1.3 binding PL/SQL indexed table IN OUT', function(done) {
async.series([
function(callback) {
var proc = "CREATE OR REPLACE PACKAGE\n" +
Expand Down Expand Up @@ -177,7 +247,7 @@ describe('43. PL/SQL binds', function() {
], done);
});

it('43.1.3 binding PL/SQL indexed table OUT', function(done) {
it('43.1.4 binding PL/SQL indexed table OUT', function(done) {
async.series([
function(callback) {
var proc = "CREATE OR REPLACE PACKAGE\n" +
Expand Down Expand Up @@ -253,7 +323,7 @@ describe('43. PL/SQL binds', function() {
//
// Test exceptions when using PL/SQL indexed table bindings
//
it('43.1.4 binding PL/SQL indexed table exceptions', function(done) {
it('43.1.5 binding PL/SQL indexed table exceptions', function(done) {
async.series([
function(callback) {
var proc = "CREATE OR REPLACE PACKAGE\n" +
Expand Down

0 comments on commit a211c8b

Please sign in to comment.