diff --git a/lib/query.js b/lib/query.js index c1b5ee5e..71cb3b8f 100644 --- a/lib/query.js +++ b/lib/query.js @@ -63,6 +63,7 @@ Query.prototype.handleRowDescription = function(msg) { var format = field.format; this._fieldNames[i] = field.name; this._fieldConverters[i] = Types.getTypeParser(field.dataTypeID, format); + this._result.addField(field); } }; diff --git a/lib/result.js b/lib/result.js index 4eabbe7f..7a1e3c04 100644 --- a/lib/result.js +++ b/lib/result.js @@ -6,6 +6,7 @@ var Result = function() { this.rowCount = null; this.oid = null; this.rows = []; + this.fields = []; }; var matchRegexp = /([A-Za-z]+) ?(\d+ )?(\d+)?/; @@ -37,4 +38,9 @@ Result.prototype.addRow = function(row) { this.rows.push(row); }; +//Add a field definition to the result +Result.prototype.addField = function(field) { + this.fields.push(field); +}; + module.exports = Result; diff --git a/test/integration/client/no-row-result-tests.js b/test/integration/client/no-row-result-tests.js new file mode 100644 index 00000000..5555ff6f --- /dev/null +++ b/test/integration/client/no-row-result-tests.js @@ -0,0 +1,23 @@ +var helper = require(__dirname + '/test-helper'); +var pg = helper.pg; +var config = helper.config; + +test('can access results when no rows are returned', function() { + if(config.native) return false; + var checkResult = function(result) { + assert(result.fields, 'should have fields definition'); + assert.equal(result.fields.length, 1); + assert.equal(result.fields[0].name, 'val'); + assert.equal(result.fields[0].dataTypeID, 25); + pg.end(); + }; + + pg.connect(config, assert.success(function(client, done) { + var query = client.query('select $1::text as val limit 0', ['hi'], assert.success(function(result) { + checkResult(result); + done(); + })); + + assert.emits(query, 'end', checkResult); + })); +});