From 1fbe54d5f2989f1fbb0d8839b36c8718ce27cbc0 Mon Sep 17 00:00:00 2001 From: brianc Date: Tue, 12 Jul 2011 23:08:16 -0500 Subject: [PATCH] fix gh#36 --- lib/query.js | 8 +++--- test/integration/client/transaction-tests.js | 26 ++++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/lib/query.js b/lib/query.js index f68c343b..dfa5f43c 100644 --- a/lib/query.js +++ b/lib/query.js @@ -9,6 +9,8 @@ var Query = function(config) { this.rows = config.rows; this.types = config.types; this.name = config.name; + //use unique portal name each time + this.portal = config.portal || "" this.callback = config.callback; this._fieldNames = []; this._fieldConverters = []; @@ -101,7 +103,7 @@ p.hasBeenParsed = function(connection) { p.getRows = function(connection) { connection.execute({ - portal: this.name, + portal: this.portalName, rows: this.rows }, true); connection.flush(); @@ -131,14 +133,14 @@ p.prepare = function(connection) { //http://developer.postgresql.org/pgdocs/postgres/protocol-flow.html#PROTOCOL-FLOW-EXT-QUERY connection.bind({ - portal: self.name, + portal: self.portalName, statement: self.name, values: self.values }, true); connection.describe({ type: 'P', - name: self.name || "" + name: self.portalName || "" }, true); this.getRows(connection); diff --git a/test/integration/client/transaction-tests.js b/test/integration/client/transaction-tests.js index aaaaf5b1..6c90636e 100644 --- a/test/integration/client/transaction-tests.js +++ b/test/integration/client/transaction-tests.js @@ -46,3 +46,29 @@ test('a single connection transaction', function() { })) }) + +test('gh#36', function() { + var connectionString = helper.connectionString(); + helper.pg.connect(connectionString, function(err, client) { + if(err) throw err; + client.query("BEGIN"); + client.query({ + name: 'X', + text: "SELECT $1::INTEGER", + values: [0] + }, assert.calls(function(err, result) { + if(err) throw err; + assert.equal(result.rows.length, 1); + })) + client.query({ + name: 'X', + text: "SELECT $1::INTEGER", + values: [0] + }, assert.calls(function(err, result) { + if(err) throw err; + assert.equal(result.rows.length, 1); + })) + client.query("COMMIT") + client.on('drain', client.end.bind(client)) + }) +})