From 7eb4118acd278aa5459368566cb1f4834a136a0f Mon Sep 17 00:00:00 2001 From: Alexander Penev Date: Mon, 21 Nov 2016 12:36:15 +0200 Subject: [PATCH] Add additional info or statement error --- lib/protocol/ExecuteTask.js | 2 +- lib/protocol/Result.js | 29 ++++++++++++++--------------- test/lib.Result.js | 12 ++++++------ 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/lib/protocol/ExecuteTask.js b/lib/protocol/ExecuteTask.js index 8240ea2..2b7bf89 100644 --- a/lib/protocol/ExecuteTask.js +++ b/lib/protocol/ExecuteTask.js @@ -71,10 +71,10 @@ ExecuteTask.prototype.run = function run(next) { return finalize(); } self.sendExecute(function receive(err, reply) { + self.pushReply(reply); if (err) { return finalize(err); } - self.pushReply(reply); if (!self.writer.finished && reply.writeLobReply) { self.writer.update(reply.writeLobReply); } diff --git a/lib/protocol/Result.js b/lib/protocol/Result.js index 3f45d27..24fc12e 100644 --- a/lib/protocol/Result.js +++ b/lib/protocol/Result.js @@ -76,42 +76,41 @@ Result.prototype.getLobColumnNames = function getLobColumnNames() { }; Result.prototype.handle = function handle(err, reply, cb) { - if (err) { - return cb(err); - } + var reply = reply || {}; switch (reply.functionCode) { case FunctionCode.SELECT: case FunctionCode.SELECT_FOR_UPDATE: - this.handleQuery(cb, this.createResultSets(reply.resultSets)); + this.handleQuery(cb, err, this.createResultSets(reply.resultSets)); return; case FunctionCode.INSERT: case FunctionCode.UPDATE: case FunctionCode.DELETE: - this.handleModify(cb, reply.rowsAffected); + this.handleModify(cb, err, reply.rowsAffected); return; case FunctionCode.NIL: case FunctionCode.DDL: case FunctionCode.CONNECT: - cb(null); + cb(err); return; case FunctionCode.DB_PROCEDURE_CALL: case FunctionCode.DB_PROCEDURE_CALL_WITH_RESULT: this.handleDBCall(cb, + err, this.createOutputParameters(reply.outputParameters), this.createResultSets(reply.resultSets)); return; default: - err = new Error('Invalid or unsupported FunctionCode'); + err = err || new Error('Invalid or unsupported FunctionCode'); cb(err); } }; -Result.prototype.handleModify = function handleModify(cb, rowsAffected) { - cb(null, rowsAffected); +Result.prototype.handleModify = function handleModify(cb, err, rowsAffected) { + cb(err, rowsAffected); }; -Result.prototype.handleQuery = function handleQuery(cb, resultSets) { +Result.prototype.handleQuery = function handleQuery(cb, err, resultSets) { function done(err, results) { if (err) { return cb(err); @@ -121,13 +120,13 @@ Result.prototype.handleQuery = function handleQuery(cb, resultSets) { return cb.apply(null, args); } - if (!this.autoFetch) { - return done(null, resultSets); + if (!this.autoFetch || err) { + return done(err, resultSets); } fetchAll(resultSets, done); }; -Result.prototype.handleDBCall = function handleDBCall(cb, params, resultSets) { +Result.prototype.handleDBCall = function handleDBCall(cb, err, params, resultSets) { params = params || {}; function done(err, results) { @@ -139,8 +138,8 @@ Result.prototype.handleDBCall = function handleDBCall(cb, params, resultSets) { return cb.apply(null, args); } - if (!this.autoFetch) { - return done(null, resultSets); + if (!this.autoFetch || err) { + return done(err, resultSets); } function fetchResults(err) { diff --git a/test/lib.Result.js b/test/lib.Result.js index 8f993a5..9519e4a 100644 --- a/test/lib.Result.js +++ b/test/lib.Result.js @@ -188,7 +188,7 @@ describe('Lib', function () { params.should.equal(_params); rs.should.equal(resultSet); done(); - }, _params, [resultSet]); + }, null, _params, [resultSet]); }); it('should handle a db procedure call with lob instance', @@ -215,7 +215,7 @@ describe('Lib', function () { params.Z.should.equal(_buffer); rows.should.eql(_rows); done(); - }, _params, [resultSet]); + }, null, _params, [resultSet]); }); it('should handle a db procedure call with lob buffer', @@ -242,7 +242,7 @@ describe('Lib', function () { params.Z.should.equal(_buffer); rows.should.eql(_rows); done(); - }, _params, [resultSet]); + }, null, _params, [resultSet]); }); @@ -268,7 +268,7 @@ describe('Lib', function () { function (err) { err.should.equal(_err); done(); - }, _params, [resultSet]); + }, null, _params, [resultSet]); }); it('should handle a db procedure call with error', @@ -281,7 +281,7 @@ describe('Lib', function () { result.handleDBCall(function (err) { err.should.equal(_err); done(); - }, {}, [resultSet]); + }, null, {}, [resultSet]); }); @@ -295,7 +295,7 @@ describe('Lib', function () { result.handleQuery(function (err) { err.should.equal(_err); done(); - }, [resultSet]); + }, null, [resultSet]); }); }); }); \ No newline at end of file