From cafded964eca9072e70ecf9b4a57914003743810 Mon Sep 17 00:00:00 2001 From: bmc Date: Fri, 29 Oct 2010 21:33:53 -0400 Subject: [PATCH] support for 'emptyQuery' command --- lib/connection.js | 18 +++++++++++------- test/integration/client/empty-query-tests.js | 8 ++++++++ test/test-buffers.js | 4 ++++ 3 files changed, 23 insertions(+), 7 deletions(-) create mode 100644 test/integration/client/empty-query-tests.js diff --git a/lib/connection.js b/lib/connection.js index a309ee6b..a372eff4 100644 --- a/lib/connection.js +++ b/lib/connection.js @@ -198,7 +198,8 @@ var messageNames = { 1: 'parseComplete', 2: 'bindComplete', A: 'notification', - n: 'noData' + n: 'noData', + I: 'emptyQuery' }; p.parseMessage = function() { @@ -334,15 +335,18 @@ p.parseE = function(msg) { //same thing, different name p.parseN = p.parseE; +//some messages are only a header portion and +//require no more parsing +var noParse = function(msg) { return msg; }; + //parses parseComplete -p.parse1 = function(msg) { - return msg; -}; +p.parse1 = noParse; //parses bindComplete -p.parse2 = function(msg) { - return msg; -}; +p.parse2 = noParse; + +//parse emptyQuery +p.parseI = noParse; p.parseA = function(msg) { msg.processId = this.parseInt32(); diff --git a/test/integration/client/empty-query-tests.js b/test/integration/client/empty-query-tests.js new file mode 100644 index 00000000..897c01a9 --- /dev/null +++ b/test/integration/client/empty-query-tests.js @@ -0,0 +1,8 @@ +var helper = require(__dirname+'/test-helper'); +var client = helper.client(); + +test("empty query message handling", function() { + client.query(""); + assert.raises(client.connection, 'emptyQuery'); + client.on('drain', client.end.bind(client)); +}); diff --git a/test/test-buffers.js b/test/test-buffers.js index ed65e922..afef19c9 100644 --- a/test/test-buffers.js +++ b/test/test-buffers.js @@ -113,4 +113,8 @@ buffers.notification = function(id, channel, payload) { .join(true, 'A') }; +buffers.emptyQuery = function() { + return new BufferList().join(true, 'I'); +}; + module.exports = buffers;