diff --git a/lib/client.js b/lib/client.js index ac57e49b..da3924d5 100644 --- a/lib/client.js +++ b/lib/client.js @@ -150,11 +150,20 @@ p.prepare = function(connection) { return (val instanceof Date) ? JSON.stringify(val) : val; }); } + //http://developer.postgresql.org/pgdocs/postgres/protocol-flow.html#PROTOCOL-FLOW-EXT-QUERY connection.bind({ portal: self.name, statement: self.name, values: self.values }); + connection.describe({ + type: 'P', + name: self.name || "" + }); + connection.execute({ + portal: self.name, + rows: self.rows + }); connection.flush(); }; @@ -168,27 +177,10 @@ p.prepare = function(connection) { name: self.name, types: self.types }); - connection.flush(); - connection.once('parseComplete', onParseComplete); + onParseComplete(); } - var onBindComplete = function() { - connection.describe({ - type: 'P', - name: self.name || "" - }); - //http://developer.postgresql.org/pgdocs/postgres/protocol-flow.html#PROTOCOL-FLOW-EXT-QUERY - //TODO get ourselves a rowDescription for result type coercion - connection.execute({ - portal: self.name, - rows: self.rows - }); - connection.flush(); - }; - - connection.once('bindComplete', onBindComplete); - //TODO support EmptyQueryResponse, ErrorResponse, and PortalSuspended var onCommandComplete = function() { connection.sync(); diff --git a/test/integration/client/type-coercion-tests.js b/test/integration/client/type-coercion-tests.js index 41127606..b062b4b9 100644 --- a/test/integration/client/type-coercion-tests.js +++ b/test/integration/client/type-coercion-tests.js @@ -2,6 +2,7 @@ var helper = require(__dirname + '/test-helper'); var client = helper.client(); client.on('drain', client.end.bind(client)); + var testForTypeCoercion = function(type){ client.query("create temp table test_type(col " + type.name + ")"); @@ -20,7 +21,7 @@ var testForTypeCoercion = function(type){ }); assert.emits(query, 'row', function(row) { - assert.strictEqual(row.fields[0], val); + assert.strictEqual(row.fields[0], val, "expected " + type.name + " of " + val + " but got " + row.fields[0]); }); client.query({ diff --git a/test/test-helper.js b/test/test-helper.js index 7bbb424b..3ac533b9 100644 --- a/test/test-helper.js +++ b/test/test-helper.js @@ -23,7 +23,7 @@ assert.emits = function(item, eventName, callback) { test("Should have called " + eventName, function() { assert.ok(called, "Expected '" + eventName + "' to be called.") }); - },10000); + },20000); item.once(eventName, function() { called = true;