diff --git a/lib/client.js b/lib/client.js index f0a374d32..8b388063b 100644 --- a/lib/client.js +++ b/lib/client.js @@ -100,44 +100,58 @@ Client.prototype.connect = function(callback) { //delegate rowDescription to active query con.on('rowDescription', function(msg) { - self.activeQuery.handleRowDescription(msg); + if (self.activeQuery) { + self.activeQuery.handleRowDescription(msg); + } }); //delegate dataRow to active query con.on('dataRow', function(msg) { - self.activeQuery.handleDataRow(msg); + if (self.activeQuery) { + self.activeQuery.handleDataRow(msg); + } }); //delegate portalSuspended to active query con.on('portalSuspended', function(msg) { - self.activeQuery.handlePortalSuspended(con); + if (self.activeQuery) { + self.activeQuery.handlePortalSuspended(con); + } }); //deletagate emptyQuery to active query con.on('emptyQuery', function(msg) { - self.activeQuery.handleEmptyQuery(con); + if (self.activeQuery) { + self.activeQuery.handleEmptyQuery(con); + } }); //delegate commandComplete to active query con.on('commandComplete', function(msg) { - self.activeQuery.handleCommandComplete(msg, con); + if (self.activeQuery) { + 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) { + if(self.activeQuery && self.activeQuery.name) { con.parsedStatements[self.activeQuery.name] = true; } }); con.on('copyInResponse', function(msg) { - self.activeQuery.handleCopyInResponse(self.connection); + if (self.activeQuery) { + self.activeQuery.handleCopyInResponse(self.connection); + } }); con.on('copyData', function (msg) { - self.activeQuery.handleCopyData(msg, self.connection); + if (self.activeQuery) { + self.activeQuery.handleCopyData(msg, self.connection); + } }); con.on('notification', function(msg) {