Skip to content

Commit 759c6f1

Browse files
committed
Merge PR345 from @doberkofler adding Bind by Position support for PL/SQL Index-by binds
1 parent 7a79bf2 commit 759c6f1

File tree

5 files changed

+85
-8
lines changed

5 files changed

+85
-8
lines changed

src/dpi/include/dpiStmt.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,9 @@ class Stmt
176176
// methods
177177
virtual void bind(unsigned int pos, unsigned short type, void *buf,
178178
DPI_SZ_TYPE bufSize, short *ind, DPI_BUFLEN_TYPE *bufLen,
179-
void *data, cbtype cb = NULL ) = 0;
179+
unsigned int maxarr_len, unsigned int *curelen,
180+
void *data,
181+
cbtype cb = NULL ) = 0;
180182

181183
virtual void bind(const unsigned char *name, int nameLen,
182184
unsigned int bndpos,

src/dpi/src/dpiStmtImpl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ void StmtImpl::prefetchRows (unsigned int prefetchRows)
247247
*/
248248
void StmtImpl::bind (unsigned int pos, unsigned short type, void *buf,
249249
DPI_SZ_TYPE bufSize, short *ind, DPI_BUFLEN_TYPE *bufLen,
250+
unsigned int maxarr_len, unsigned int *curelen,
250251
void *data, cbtype cb)
251252
{
252253
OCIBind *b = (OCIBind *)0;
@@ -257,7 +258,7 @@ void StmtImpl::bind (unsigned int pos, unsigned short type, void *buf,
257258
(type == DpiRSet) ? 0 : bufSize, type,
258259
(cb ? NULL : ind),
259260
(cb ? NULL : bufLen),
260-
NULL, 0, NULL,
261+
NULL, maxarr_len, curelen,
261262
(cb) ? OCI_DATA_AT_EXEC : OCI_DEFAULT),
262263
errh_);
263264

src/dpi/src/dpiStmtImpl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class StmtImpl : public Stmt
7777

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

8283
virtual void bind (const unsigned char *name, int nameLen,

src/njs/src/njsConnection.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,6 +1744,10 @@ void Connection::PrepareAndBind (eBaton* executeBaton)
17441744
executeBaton->binds[index]->maxSize,
17451745
executeBaton->binds[index]->ind,
17461746
executeBaton->binds[index]->len,
1747+
(executeBaton->binds[index]->isArray) ?
1748+
executeBaton->binds[index]->maxArraySize : 0,
1749+
(executeBaton->binds[index]->isArray) ?
1750+
&(executeBaton->binds[index]->curArraySize ) : 0,
17471751
(executeBaton->stmtIsReturning &&
17481752
executeBaton->binds[index]->isOut ) ?
17491753
(void *)executeBaton : NULL,

test/plsqlBinding.js

Lines changed: 75 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ describe('43. plsqlBinding.js', function() {
6565
});
6666
})
6767

68-
it('43.1.1 binding PL/SQL indexed table IN', function(done) {
68+
it('43.1.1 binding PL/SQL indexed table IN by name', function(done) {
6969
async.series([
7070
function(callback) {
7171
var proc = "CREATE OR REPLACE PACKAGE\n" +
@@ -139,7 +139,77 @@ describe('43. plsqlBinding.js', function() {
139139
], done);
140140
});
141141

142-
it('43.1.2 binding PL/SQL indexed table IN OUT', function(done) {
142+
it('43.1.2 binding PL/SQL indexed table IN by position', function(done) {
143+
async.series([
144+
function(callback) {
145+
var proc = "CREATE OR REPLACE PACKAGE\n" +
146+
"oracledb_testpack\n" +
147+
"IS\n" +
148+
" TYPE stringsType IS TABLE OF VARCHAR2(30) INDEX BY BINARY_INTEGER;\n" +
149+
" TYPE numbersType IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;\n" +
150+
" PROCEDURE test(s IN stringsType, n IN numbersType);\n" +
151+
"END;";
152+
connection.should.be.ok;
153+
connection.execute(
154+
proc,
155+
function(err) {
156+
should.not.exist(err);
157+
callback();
158+
}
159+
);
160+
},
161+
function(callback) {
162+
var proc = "CREATE OR REPLACE PACKAGE BODY\n" +
163+
"oracledb_testpack\n" +
164+
"IS\n" +
165+
" PROCEDURE test(s IN stringsType, n IN numbersType)\n" +
166+
" IS\n" +
167+
" BEGIN\n" +
168+
" IF (s(1) IS NULL OR s(1) <> 'John') THEN\n" +
169+
" raise_application_error(-20000, 'Invalid s(1): \"' || s(1) || '\"');\n" +
170+
" END IF;\n" +
171+
" IF (s(2) IS NULL OR s(2) <> 'Doe') THEN\n" +
172+
" raise_application_error(-20000, 'Invalid s(2): \"' || s(2) || '\"');\n" +
173+
" END IF;\n" +
174+
" END;\n" +
175+
"END;";
176+
connection.should.be.ok;
177+
connection.execute(
178+
proc,
179+
function(err) {
180+
should.not.exist(err);
181+
callback();
182+
}
183+
);
184+
},
185+
function(callback) {
186+
var bindvars = [
187+
{type: oracledb.STRING, dir: oracledb.BIND_IN, val: ['John', 'Doe']},
188+
{type: oracledb.NUMBER, dir: oracledb.BIND_IN, val: [8, 11]}
189+
];
190+
connection.execute(
191+
"BEGIN oracledb_testpack.test(:1, :2); END;",
192+
bindvars,
193+
function(err, result) {
194+
should.not.exist(err);
195+
// console.log(result);
196+
callback();
197+
}
198+
);
199+
},
200+
function(callback) {
201+
connection.execute(
202+
"DROP PACKAGE oracledb_testpack",
203+
function(err) {
204+
should.not.exist(err);
205+
callback();
206+
}
207+
);
208+
}
209+
], done);
210+
});
211+
212+
it('43.1.3 binding PL/SQL indexed table IN OUT', function(done) {
143213
async.series([
144214
function(callback) {
145215
var proc = "CREATE OR REPLACE PACKAGE\n" +
@@ -212,7 +282,7 @@ describe('43. plsqlBinding.js', function() {
212282
], done);
213283
});
214284

215-
it('43.1.3 binding PL/SQL indexed table OUT', function(done) {
285+
it('43.1.4 binding PL/SQL indexed table OUT', function(done) {
216286
async.series([
217287
function(callback) {
218288
var proc = "CREATE OR REPLACE PACKAGE\n" +
@@ -487,9 +557,8 @@ describe('43. plsqlBinding.js', function() {
487557
"BEGIN oracledb_testpack.test4(:1); END;",
488558
bindvars,
489559
function(err, result) {
490-
should.exist(err);
491-
(err.message).should.startWith('ORA-06550'); // this causes a PL/SQL syntax error
492-
should.not.exist(result);
560+
should.not.exist(err);
561+
should.exist(result);
493562
done();
494563
}
495564
);

0 commit comments

Comments
 (0)