Fix query error emit on native bindings

This commit is contained in:
Brian M. Carlson 2014-04-06 12:55:26 -05:00
parent 6d64abc0e2
commit bd74d48791
2 changed files with 4 additions and 1 deletions

View File

@ -27,6 +27,7 @@ var NativeQuery = function(config, values, callback) {
this._result = new Result(config.rowMode);
this._addedFields = false;
this._hadError = false;
//normalize values
if(this.values) {
for(var i = 0, len = this.values.length; i < len; i++) {
@ -55,6 +56,7 @@ NativeQuery.prototype.handleError = function(error) {
error = this._canceledDueToError;
this._canceledDueToError = false;
}
this._hadError = true;
if(this.callback) {
var cb = this.callback;
//remove callback to prevent double call on readyForQuery
@ -66,6 +68,7 @@ NativeQuery.prototype.handleError = function(error) {
};
NativeQuery.prototype.handleReadyForQuery = function(meta) {
if(this._hadError) return;
if (this._canceledDueToError) {
return this.handleError(this._canceledDueToError);
}

View File

@ -20,7 +20,7 @@ test('error during query execution', function() {
//because it was killed and received an error
//https://github.com/brianc/node-postgres/issues/547
query1.on('end', function() {
assert.fail('Client with an error should not emit "end" event')
assert.fail('Query with an error should not emit "end" event')
})
var client2 = new Client(helper.args);
client2.connect(assert.success(function() {