Skip to content

Commit 740f5bf

Browse files
committed
More REF CURSOR refactoring
1 parent 0fafee7 commit 740f5bf

File tree

5 files changed

+74
-25
lines changed

5 files changed

+74
-25
lines changed

src/njs/src/njsConnection.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -941,14 +941,19 @@ void Connection::Async_Execute (uv_work_t *req)
941941

942942
if ( bind->isOut && bind->type == dpi::DpiRSet )
943943
{
944-
bind->flags =
945-
(((Stmt*)bind->value)->getState () == DpiStmtStateExecuted ) ?
946-
NJS_BIND_REF_CURSOR_VALID : NJS_BIND_REF_CURSOR_INVALID ;
947-
if ( ( bind->flags == NJS_BIND_REF_CURSOR_INVALID ) &&
948-
( bind->value != NULL ) )
944+
unsigned long state = ((Stmt*)bind->value)->getState ();
945+
946+
if ( state == DPI_STMT_STATE_EXECUTED )
947+
{
948+
// set the prefetch on the valid cursor object
949+
((dpi::Stmt *)(bind->value))->prefetchRows (
950+
executeBaton->prefetchRows ) ;
951+
}
952+
else
949953
{
950954
/* Release the invalid REFCURSOR to avoid any leaks */
951955
((Stmt*)bind->value)->release ();
956+
bind->value = NULL;
952957
}
953958
}
954959
}
@@ -1825,8 +1830,8 @@ void Connection::Async_AfterExecute(uv_work_t *req)
18251830
/* ResultSet case, the statement object is ready for fetching */
18261831
(ObjectWrap::Unwrap<ResultSet> (resultSet))->
18271832
setResultSet( executeBaton->dpistmt,
1828-
executeBaton,
1829-
BIND_FLAGS_STMT_READY );
1833+
executeBaton);
1834+
18301835
result->Set(NanNew<v8::String>("resultSet"), resultSet );
18311836
}
18321837
else
@@ -2059,11 +2064,7 @@ Handle<Value> Connection::GetValueRefCursor ( eBaton *executeBaton,
20592064
GetFunction() ->NewInstance();
20602065
(ObjectWrap::Unwrap<ResultSet> (resultSet))->
20612066
setResultSet( (dpi::Stmt*)(bind->value),
2062-
executeBaton,
2063-
bind->flags );
2064-
2065-
// set the prefetch on the cursor object
2066-
((dpi::Stmt*)(bind->value))->prefetchRows(executeBaton->prefetchRows);
2067+
executeBaton);
20672068
value = resultSet;
20682069
}
20692070
else

src/njs/src/njsConnection.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,6 @@ using namespace dpi;
6666
class Connection;
6767
class ProtoILob;
6868

69-
/* Flags Constants */
70-
#define NJS_BIND_REF_CURSOR_INVALID 0 /*CURSOR not-fetch-able */
71-
#define NJS_BIND_REF_CURSOR_VALID 1 /*CURSOR fetch-able */
72-
7369
/**
7470
* Structure used for binds
7571
**/
@@ -87,12 +83,11 @@ typedef struct Bind
8783
bool isInOut; // Date/Timestamp needs this info
8884
unsigned int rowsReturned; /* number rows returned for
8985
the bind (DML RETURNING) */
90-
unsigned long flags; // Flags applicable for this BIND
9186
dpi::DateTimeArray* dttmarr;
9287

9388
Bind () : key(""), value(NULL), extvalue (NULL), len(NULL), len2(NULL),
9489
maxSize(0), type(0), ind(NULL), isOut(false), isInOut(false),
95-
rowsReturned(0), flags(BIND_FLAGS_STMT_NOT_READY), dttmarr ( NULL )
90+
rowsReturned(0), dttmarr ( NULL )
9691
{}
9792
}Bind;
9893

src/njs/src/njsResultSet.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,18 @@ Persistent<FunctionTemplate> ResultSet::resultSetTemplate_s;
6868
stmt - dpi statement
6969
executeBaton - eBaton structure
7070
*/
71-
void ResultSet::setResultSet ( dpi::Stmt *stmt, eBaton *executeBaton,
72-
unsigned long flags )
71+
void ResultSet::setResultSet ( dpi::Stmt *stmt, eBaton *executeBaton )
7372
{
7473
this->dpistmt_ = stmt;
7574
this->dpienv_ = executeBaton->dpienv;
7675
this->njsconn_ = executeBaton->njsconn;
77-
if ( flags == NJS_BIND_REF_CURSOR_VALID )
76+
if ( stmt )
7877
{
7978
this->meta_ = stmt->getMetaData();
8079
this->numCols_ = this->dpistmt_->numCols();
8180
this->state_ = INACTIVE;
8281
}
83-
else if ( flags == NJS_BIND_REF_CURSOR_INVALID )
82+
else
8483
{
8584
/*
8685
* This could happen in REFCURSOR case, when the stored procedure

src/njs/src/njsResultSet.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,7 @@ class ResultSet: public ObjectWrap {
104104

105105
static void Init(Handle<Object> target);
106106

107-
void setResultSet ( dpi::Stmt *dpistmt, eBaton *executebaton,
108-
unsigned long flags );
109-
107+
void setResultSet ( dpi::Stmt *dpistmt, eBaton *executebaton );
110108

111109
// Define ResultSet Constructor
112110
static Persistent<FunctionTemplate> resultSetTemplate_s ;

test/resultSet2.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ describe('55. resultSet2.js', function() {
8888
WHERE employees_id > p_in; \
8989
END; ";
9090

91+
var proc2 =
92+
"CREATE OR REPLACE PROCEDURE get_invalid_refcur ( p OUT SYS_REFCURSOR) \
93+
AS \
94+
BEGIN \
95+
NULL; \
96+
END; ";
97+
9198
beforeEach(function(done) {
9299
async.series([
93100
function(callback) {
@@ -130,6 +137,17 @@ describe('55. resultSet2.js', function() {
130137
callback();
131138
}
132139
);
140+
},
141+
function(callback) {
142+
connection.execute (
143+
proc2,
144+
[],
145+
{ autoCommit : true },
146+
function (err ) {
147+
should.not.exist ( err );
148+
callback();
149+
}
150+
);
133151
}
134152
], done);
135153
})
@@ -154,6 +172,16 @@ describe('55. resultSet2.js', function() {
154172
}
155173
);
156174
},
175+
function(callback) {
176+
connection.execute (
177+
'DROP PROCEDURE get_invalid_refcur',
178+
function ( err ) {
179+
should.not.exist ( err ) ;
180+
callback ();
181+
}
182+
);
183+
},
184+
157185
function(callback) {
158186
connection.release( function(err) {
159187
should.not.exist(err);
@@ -340,11 +368,39 @@ describe('55. resultSet2.js', function() {
340368
}
341369
}
342370
})
371+
372+
it ( '55.3.3 Invalid REF Cursor', function (done ) {
373+
connection.should.be.ok;
374+
375+
connection.execute (
376+
"BEGIN get_invalid_refcur ( :p ); END; ",
377+
{
378+
p : { type : oracledb.CURSOR, dir : oracledb.BIND_OUT }
379+
},
380+
function ( err, result) {
381+
should.not.exist ( err );
382+
fetchRowFromRS2 (result.outBinds.out, done);
383+
});
384+
385+
386+
function fetchRowFromRS2 (rs, cb ) {
387+
if ( rs ) {
388+
rs.getRow ( function ( err, row ) {
389+
should.not.exist ( err ) ;
390+
if ( row ) {
391+
return fetchRowFromRS (rs, cb );
392+
}
393+
});
394+
}
395+
cb();
396+
}
397+
});
343398
})
344399

345400
describe('55.4 release connection before close resultSet', function() {
346401
var conn2 = false;
347402
function fetchRowFromRS(rs, cb) {
403+
348404
rs.getRow(function(err, row) {
349405
if(row) {
350406
return fetchRowFromRS(rs, cb);

0 commit comments

Comments
 (0)