diff --git a/lib/query.js b/lib/query.js index d68f3229..4e5cb8bd 100644 --- a/lib/query.js +++ b/lib/query.js @@ -61,7 +61,7 @@ p.submit = function(connection) { }; var onReadyForQuery = function() { - //remove all listeners + //remove all listeners connection.removeListener('rowDescription', handleRowDescription); connection.removeListener('dataRow', handleDatarow); connection.removeListener('readyForQuery', onReadyForQuery); @@ -110,29 +110,28 @@ p.prepare = function(connection) { name: self.name || "" }); - //TODO test for & support multpile row requests - connection.execute({ - portal: self.name, - rows: self.rows - }); + var getRows = function() { + connection.execute({ + portal: self.name, + rows: self.rows + }); + connection.flush(); + }; - connection.flush(); + getRows(); //TODO support EmptyQueryResponse, ErrorResponse, and PortalSuspended var onCommandComplete = function() { - connection.removeListener('error', onError); + connection.removeListener('error', onCommandComplete); connection.removeListener('commandComplete', onCommandComplete); + connection.removeListener('portalSuspended', getRows); connection.sync(); }; - var onError = function() { - connection.removeListener('error', onError); - connection.removeListener('commandComplete', onCommandComplete); - connection.sync(); - }; + connection.on('portalSuspended', getRows); connection.on('commandComplete', onCommandComplete); - connection.on('error', onError); + connection.on('error', onCommandComplete); }; var dateParser = function(isoDate) { diff --git a/test/integration/client/prepared-statement-tests.js b/test/integration/client/prepared-statement-tests.js index c6d1c5ab..5d197a55 100644 --- a/test/integration/client/prepared-statement-tests.js +++ b/test/integration/client/prepared-statement-tests.js @@ -152,3 +152,33 @@ test("prepared statements on different clients", function() { }); +test('prepared statement', function() { + var client = helper.client(); + client.on('drain', client.end.bind(client)); + client.query('CREATE TEMP TABLE zoom(name varchar(100));'); + client.query("INSERT INTO zoom (name) VALUES ('zed')"); + client.query("INSERT INTO zoom (name) VALUES ('postgres')"); + client.query("INSERT INTO zoom (name) VALUES ('node postgres')"); + + test('with small row count', function() { + var q = client.query({ + name: 'get names', + text: "SELECT name FROM zoom ORDER BY name", + rows: 1 + }); + test('row callback fires for each result', function() { + assert.emits(q, 'row', function(row) { + assert.equal(row.name, 'node postgres'); + + assert.emits(q, 'row', function(row) { + assert.equal(row.name, 'postgres'); + + assert.emits(q, 'row', function(row) { + assert.equal(row.name, 'zed'); + }) + }); + }) + }) + + }) +})