Skip to content

Commit 5edd92b

Browse files
committed
Merge pull request brianc#668 from brianc/issues/600-redux
Fix issue with parsed statement cache timing - closes brianc#665
2 parents eeae8e6 + 9e2a3e5 commit 5edd92b

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

lib/client.js

+9
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,15 @@ Client.prototype.connect = function(callback) {
117117
self.activeQuery.handleCommandComplete(msg, con);
118118
});
119119

120+
//if a prepared statement has a name and properly parses
121+
//we track that its already been executed so we don't parse
122+
//it again on the same client
123+
con.on('parseComplete', function(msg) {
124+
if(self.activeQuery.name) {
125+
con.parsedStatements[self.activeQuery.name] = true;
126+
}
127+
});
128+
120129
con.on('copyInResponse', function(msg) {
121130
self.activeQuery.handleCopyInResponse(self.connection);
122131
});

lib/query.js

-3
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,6 @@ Query.prototype.handleDataRow = function(msg) {
6767
};
6868

6969
Query.prototype.handleCommandComplete = function(msg, con) {
70-
if(this.name) {
71-
con.parsedStatements[this.name] = true;
72-
}
7370
this._result.addCommandComplete(msg);
7471
//need to sync after each command complete of a prepared statement
7572
if(this.isPreparedStatement) {

test/integration/gh-issues/600-tests.js

+22-3
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,25 @@ var steps = [
5353
insertDataBar
5454
]
5555

56-
async.series(steps, assert.success(function() {
57-
db.end()
58-
}))
56+
test('test if query fails', function() {
57+
async.series(steps, assert.success(function() {
58+
db.end()
59+
}))
60+
})
61+
62+
test('test if prepare works but bind fails', function() {
63+
var client = helper.client();
64+
var q = {
65+
text: 'SELECT $1::int as name',
66+
values: ['brian'],
67+
name: 'test'
68+
};
69+
client.query(q, assert.calls(function(err, res) {
70+
q.values = [1];
71+
client.query(q, assert.calls(function(err, res) {
72+
assert.ifError(err);
73+
client.end();
74+
}));
75+
}));
76+
});
77+

0 commit comments

Comments
 (0)