Fix issue with parsed statement cache timing - closes #665

This commit is contained in:
Brian M. Carlson 2014-10-21 13:50:49 -04:00
parent eeae8e6f57
commit 9e2a3e599b
3 changed files with 31 additions and 6 deletions

View File

@ -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);
});

View File

@ -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) {

View File

@ -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();
}));
}));
});