Skip to content

Commit 1fbe54d

Browse files
committed
fix gh#36
1 parent f395ee6 commit 1fbe54d

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

lib/query.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ var Query = function(config) {
99
this.rows = config.rows;
1010
this.types = config.types;
1111
this.name = config.name;
12+
//use unique portal name each time
13+
this.portal = config.portal || ""
1214
this.callback = config.callback;
1315
this._fieldNames = [];
1416
this._fieldConverters = [];
@@ -101,7 +103,7 @@ p.hasBeenParsed = function(connection) {
101103

102104
p.getRows = function(connection) {
103105
connection.execute({
104-
portal: this.name,
106+
portal: this.portalName,
105107
rows: this.rows
106108
}, true);
107109
connection.flush();
@@ -131,14 +133,14 @@ p.prepare = function(connection) {
131133

132134
//http://developer.postgresql.org/pgdocs/postgres/protocol-flow.html#PROTOCOL-FLOW-EXT-QUERY
133135
connection.bind({
134-
portal: self.name,
136+
portal: self.portalName,
135137
statement: self.name,
136138
values: self.values
137139
}, true);
138140

139141
connection.describe({
140142
type: 'P',
141-
name: self.name || ""
143+
name: self.portalName || ""
142144
}, true);
143145

144146
this.getRows(connection);

test/integration/client/transaction-tests.js

+26
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,29 @@ test('a single connection transaction', function() {
4646

4747
}))
4848
})
49+
50+
test('gh#36', function() {
51+
var connectionString = helper.connectionString();
52+
helper.pg.connect(connectionString, function(err, client) {
53+
if(err) throw err;
54+
client.query("BEGIN");
55+
client.query({
56+
name: 'X',
57+
text: "SELECT $1::INTEGER",
58+
values: [0]
59+
}, assert.calls(function(err, result) {
60+
if(err) throw err;
61+
assert.equal(result.rows.length, 1);
62+
}))
63+
client.query({
64+
name: 'X',
65+
text: "SELECT $1::INTEGER",
66+
values: [0]
67+
}, assert.calls(function(err, result) {
68+
if(err) throw err;
69+
assert.equal(result.rows.length, 1);
70+
}))
71+
client.query("COMMIT")
72+
client.on('drain', client.end.bind(client))
73+
})
74+
})

0 commit comments

Comments
 (0)