Skip to content

Fix issue with parsed statement cache timing - closes #665 #668

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 21, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
3 changes: 0 additions & 3 deletions lib/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
25 changes: 22 additions & 3 deletions test/integration/gh-issues/600-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}));
}));
});