Skip to content

Commit 0d885e5

Browse files
committed
fixed reader JS bindings so that reader handle gets destructed
1 parent 210c4ba commit 0d885e5

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

lib/oracle.js

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,36 @@ exports.OCCITIMESTAMP = 7;
3535
exports.OCCINUMBER = 8;
3636
exports.OCCIBLOB = 9;
3737

38-
// Reader.prototype.nextRow is implemented in JS rather than C++.
39-
// This is easier and also more efficient because we don't cross the JS/C++ boundary every time
40-
// we read a record.
41-
bindings.Reader.prototype.nextRow = function(cb) {
38+
// Reader is implemented in JS around a C++ handle
39+
// This is easier and also more efficient because we don't cross the JS/C++ boundary
40+
// every time we read a record.
41+
function Reader(handle) {
42+
this._handle = handle;
43+
this._error = null;
44+
this._rows = [];
45+
}
46+
47+
Reader.prototype.nextRows = function(cb, count) {
48+
this._handle.nextRows(cb, count);
49+
}
50+
51+
Reader.prototype.nextRow = function(cb) {
4252
var self = this;
43-
if (self._error || (self._rows && self._rows.length > 0)) {
53+
if (!self._handle || self._error || (self._rows && self._rows.length > 0)) {
4454
process.nextTick(function() {
4555
cb(self._error, self._rows && self._rows.shift());
4656
});
4757
} else {
4858
// nextRows willl use the prefetch row count as window size
49-
self.nextRows(function(err, result) {
59+
self._handle.nextRows(function(err, result) {
5060
self._error = err || self._error;
5161
self._rows = result;
62+
if (err || result.length === 0) self._handle = null;
5263
cb(self._error, self._rows && self._rows.shift());
5364
});
5465
}
5566
};
67+
68+
bindings.Connection.prototype.reader = function(sql, args) {
69+
return new Reader(this.readerHandle(sql, args));
70+
}

src/connection.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ void Connection::Init(Handle<Object> target) {
2222

2323
NODE_SET_PROTOTYPE_METHOD(uni::Deref(constructorTemplate), "execute", Execute);
2424
NODE_SET_PROTOTYPE_METHOD(uni::Deref(constructorTemplate), "executeSync", ExecuteSync);
25-
NODE_SET_PROTOTYPE_METHOD(uni::Deref(constructorTemplate), "reader", CreateReader);
25+
NODE_SET_PROTOTYPE_METHOD(uni::Deref(constructorTemplate), "readerHandle", CreateReader);
2626
NODE_SET_PROTOTYPE_METHOD(uni::Deref(constructorTemplate), "close", Close);
2727
NODE_SET_PROTOTYPE_METHOD(uni::Deref(constructorTemplate), "isConnected", IsConnected);
2828
NODE_SET_PROTOTYPE_METHOD(uni::Deref(constructorTemplate), "setAutoCommit", SetAutoCommit);

0 commit comments

Comments
 (0)