diff --git a/.gitignore b/.gitignore index a86636e76..bfc1efa34 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /.emacs-project +*.swp diff --git a/lib/query.js b/lib/query.js index e8a458a11..66b617203 100644 --- a/lib/query.js +++ b/lib/query.js @@ -43,7 +43,7 @@ p.submit = function(connection) { }; }; var handleDatarow = function(msg) { - var result = []; + var result = {}; for(var i = 0; i < msg.fields.length; i++) { var rawValue = msg.fields[i]; result[names[i]] = rawValue === null ? null : converters[i](rawValue); diff --git a/test/integration/client/simple-query-tests.js b/test/integration/client/simple-query-tests.js index 0452bc9f0..a04590940 100644 --- a/test/integration/client/simple-query-tests.js +++ b/test/integration/client/simple-query-tests.js @@ -4,7 +4,7 @@ test("simple query interface", function() { var client = helper.client(); - var query = client.query("select name from person"); + var query = client.query("select name from person order by name"); client.on('drain', client.end.bind(client)); @@ -12,6 +12,17 @@ test("simple query interface", function() { query.on('row', function(row) { rows.push(row['name']) }); + query.once('row', function(row) { + test('Can iterate through columns', function () { + var columnCount = 0; + for (column in row) { + columnCount++; + }; + if ('length' in row) { + assert.length(row, columnCount, 'Iterating through the columns gives a different length from calling .length.'); + } + }); + }); assert.emits(query, 'end', function() { test("returned right number of rows", function() { diff --git a/test/integration/client/test-helper.js b/test/integration/client/test-helper.js index 03ace9136..3e7785aba 100644 --- a/test/integration/client/test-helper.js +++ b/test/integration/client/test-helper.js @@ -10,6 +10,17 @@ module.exports = { host: helper.args.host, port: helper.args.port }); + client.on('error', function(e, d) { + console.log(e); + }); + var rawQuery = client.query; + client.query = function() { + var q = rawQuery.apply(this, arguments); + q.on('error', function(e) { + console.log(e); + }); + return q; + }; client.connect(); return client; }, diff --git a/test/test-helper.js b/test/test-helper.js index 7e32022b0..6c85558a7 100644 --- a/test/test-helper.js +++ b/test/test-helper.js @@ -10,6 +10,15 @@ buffers = require(__dirname + '/test-buffers'); Connection = require('connection'); var args = require(__dirname + '/cli'); +process.on('uncaughtException', function(d) { + if ('stack' in d && 'message' in d) { + console.log("Message: " + d.message); + console.log(d.stack); + } else { + console.log(d); + } +}); + assert.same = function(actual, expected) { for(var key in expected) { assert.equal(actual[key], expected[key]); @@ -102,6 +111,7 @@ assert.isNull = function(item, message) { test = function(name, action) { test.testCount ++; + console.log('\n' + name); var result = action(); if(result === false) { test.ignored.push(name);