From f7b65723992002bfa69134e39e587569cf15e6b7 Mon Sep 17 00:00:00 2001 From: Stephen Sugden Date: Wed, 21 May 2014 21:54:27 +0200 Subject: [PATCH 1/4] fix typo --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 71a4223f..5ea42cf1 100644 --- a/index.js +++ b/index.js @@ -103,7 +103,7 @@ Cursor.prototype._getRows = function(rows, cb) { } Cursor.prototype.end = function(cb) { - if(this.statue != 'initialized') { + if(this.state != 'initialized') { this.connection.sync() } this.connection.end() From 9cc3e527da5fb8c2a2cfeb1880f4db77aacf7160 Mon Sep 17 00:00:00 2001 From: Stephen Sugden Date: Wed, 21 May 2014 22:42:35 +0200 Subject: [PATCH 2/4] add failing test for noData queries --- test/no-data-handling.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 test/no-data-handling.js diff --git a/test/no-data-handling.js b/test/no-data-handling.js new file mode 100644 index 00000000..9bcbef83 --- /dev/null +++ b/test/no-data-handling.js @@ -0,0 +1,25 @@ +var assert = require('assert') +var pg = require('pg.js'); +var Cursor = require('../'); + +describe('queries with no data', function () { + beforeEach(function(done) { + var client = this.client = new pg.Client() + client.connect(done) + }) + + + afterEach(function() { + this.client.end() + }) + + it('handles queries that return no data', function (done) { + var cursor = new Cursor('CREATE TEMPORARY TABLE whatwhat (thing int)') + this.client.query(cursor) + cursor.read(100, function (err, rows) { + assert.ifError(err) + assert.equal(rows.length, 0) + done() + }) + }); +}); From 5084624e8d5be0439fb77e6d89aaebd1530a5f40 Mon Sep 17 00:00:00 2001 From: Stephen Sugden Date: Wed, 21 May 2014 22:42:54 +0200 Subject: [PATCH 3/4] fix test command in package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a886f903..5485318d 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "test": "test" }, "scripts": { - "test": "node test/" + "test": "mocha test/" }, "author": "Brian M. Carlson", "license": "MIT", From 8283fd9b22d8ab480b9e8c8b9d38cacbca223232 Mon Sep 17 00:00:00 2001 From: Stephen Sugden Date: Wed, 21 May 2014 22:44:51 +0200 Subject: [PATCH 4/4] add support for queries that don't return a row description --- index.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 5ea42cf1..2d8e088b 100644 --- a/index.js +++ b/index.js @@ -32,14 +32,28 @@ Cursor.prototype.submit = function(connection) { }, true) con.flush() + + con.once('noData', ifNoData) + con.once('rowDescription', function () { + con.removeListener('noData', ifNoData); + }); + + function ifNoData () { + self.state = 'idle' + self._shiftQueue(); + } +} + +Cursor.prototype._shiftQueue = function () { + if(this._queue.length) { + this._getRows.apply(this, this._queue.shift()) + } } Cursor.prototype.handleRowDescription = function(msg) { this._result.addFields(msg.fields) this.state = 'idle' - if(this._queue.length) { - this._getRows.apply(this, this._queue.shift()) - } + this._shiftQueue(); } Cursor.prototype.handleDataRow = function(msg) {