From 5650b02993cd101147a8692227e53bba3c2d7e09 Mon Sep 17 00:00:00 2001 From: brianc Date: Sat, 23 Oct 2010 15:07:26 -0500 Subject: [PATCH] initial work on binding --- lib/client.js | 18 ++++++++++++++++++ test/unit/parser-tests.js | 1 + test/unit/prepared-query-tests.js | 16 +++++++++++++++- 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/lib/client.js b/lib/client.js index 0ef22a95..17d72601 100644 --- a/lib/client.js +++ b/lib/client.js @@ -129,6 +129,24 @@ p.parse = function(query) { return this; }; +p.bind = function(config) { + //normalize config + config = config || {}; + config.portalName = config.portalName || ''; + config.statementName = config.statementName || ''; + config.values = config.values || []; + var buffer = new BufferList() + .addCString(config.portalName) + .addCString(config.statementName) + .addInt16(0) //always use default text format + .addInt16(0); //number of parameters + if(config.values.length > 0) { + sys.debug("Not supporting parameters yet"); + } + buffer.addInt16(0); //no format codes, use text + this.send('B', buffer.join()); +}; + p.pulseQueryQueue = function(ready) { if(!this.readyForQuery) { return; diff --git a/test/unit/parser-tests.js b/test/unit/parser-tests.js index 756d8481..578e4e5d 100644 --- a/test/unit/parser-tests.js +++ b/test/unit/parser-tests.js @@ -10,6 +10,7 @@ var readyForQueryBuffer = buffers.readyForQuery(); var backendKeyDataBuffer = buffers.backendKeyData(1,2); var commandCompleteBuffer = buffers.commandComplete("SELECT 3"); + var addRow = function(bufferList, name, offset) { return bufferList.addCString(name) //field name .addInt32(offset++) //table id diff --git a/test/unit/prepared-query-tests.js b/test/unit/prepared-query-tests.js index 092c0622..ec125e8f 100644 --- a/test/unit/prepared-query-tests.js +++ b/test/unit/prepared-query-tests.js @@ -40,7 +40,21 @@ test('prepared queries', function() { //server raises parse complete message test('sends bind message', function() { - return false; + + test('binding to unnamed prepared statement with no values', function() { + + client.bind(); + assert.length(client.stream.packets, 1); + var packet = client.stream.packets.pop(); + var expectedBuffer = new BufferList() + .addCString("") + .addCString("") + .addInt16(0) + .addInt16(0) + .addInt16(0).join(true,"B"); + assert.equalBuffers(packet, expectedBuffer); + }); + }); test('recieves rows', function() {