From 9e2a3e599bede76ae5351f807310385521516afe Mon Sep 17 00:00:00 2001 From: "Brian M. Carlson" Date: Tue, 21 Oct 2014 13:50:49 -0400 Subject: [PATCH] Fix issue with parsed statement cache timing - closes #665 --- lib/client.js | 9 +++++++++ lib/query.js | 3 --- test/integration/gh-issues/600-tests.js | 25 ++++++++++++++++++++++--- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/lib/client.js b/lib/client.js index dfce393..a512e26 100644 --- a/lib/client.js +++ b/lib/client.js @@ -117,6 +117,15 @@ Client.prototype.connect = function(callback) { self.activeQuery.handleCommandComplete(msg, con); }); + //if a prepared statement has a name and properly parses + //we track that its already been executed so we don't parse + //it again on the same client + con.on('parseComplete', function(msg) { + if(self.activeQuery.name) { + con.parsedStatements[self.activeQuery.name] = true; + } + }); + con.on('copyInResponse', function(msg) { self.activeQuery.handleCopyInResponse(self.connection); }); diff --git a/lib/query.js b/lib/query.js index 841e9a4..1eb47b4 100644 --- a/lib/query.js +++ b/lib/query.js @@ -67,9 +67,6 @@ Query.prototype.handleDataRow = function(msg) { }; Query.prototype.handleCommandComplete = function(msg, con) { - if(this.name) { - con.parsedStatements[this.name] = true; - } this._result.addCommandComplete(msg); //need to sync after each command complete of a prepared statement if(this.isPreparedStatement) { diff --git a/test/integration/gh-issues/600-tests.js b/test/integration/gh-issues/600-tests.js index faf8fd8..0476d42 100644 --- a/test/integration/gh-issues/600-tests.js +++ b/test/integration/gh-issues/600-tests.js @@ -53,6 +53,25 @@ var steps = [ insertDataBar ] -async.series(steps, assert.success(function() { - db.end() -})) +test('test if query fails', function() { + async.series(steps, assert.success(function() { + db.end() + })) +}) + +test('test if prepare works but bind fails', function() { + var client = helper.client(); + var q = { + text: 'SELECT $1::int as name', + values: ['brian'], + name: 'test' + }; + client.query(q, assert.calls(function(err, res) { + q.values = [1]; + client.query(q, assert.calls(function(err, res) { + assert.ifError(err); + client.end(); + })); + })); +}); +