mirror of
https://github.com/brianc/node-postgres.git
synced 2025-12-08 20:16:25 +00:00
Merge pull request #5 from grncdr/no-row-description
Work with queries that don't have row descriptions
This commit is contained in:
commit
8bfd3a5bde
22
index.js
22
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) {
|
||||
@ -103,7 +117,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()
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
"test": "test"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "node test/"
|
||||
"test": "mocha test/"
|
||||
},
|
||||
"author": "Brian M. Carlson",
|
||||
"license": "MIT",
|
||||
|
||||
25
test/no-data-handling.js
Normal file
25
test/no-data-handling.js
Normal file
@ -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()
|
||||
})
|
||||
});
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user