Skip to content

Commit 831dfb1

Browse files
Justin Jaffraybrianc
Justin Jaffray
authored andcommitted
Pass through portal properly
This happened to work before because `Query.portalName` was undefined, but in order to be able to set the portal explicitly it should be using `Query.portal`.
1 parent 9389527 commit 831dfb1

File tree

2 files changed

+72
-5
lines changed

2 files changed

+72
-5
lines changed

lib/query.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ Query.prototype.handlePortalSuspended = function (connection) {
175175

176176
Query.prototype._getRows = function (connection, rows) {
177177
connection.execute({
178-
portal: this.portalName,
178+
portal: this.portal,
179179
rows: rows
180180
}, true)
181181
connection.flush()
@@ -201,15 +201,15 @@ Query.prototype.prepare = function (connection) {
201201

202202
// http://developer.postgresql.org/pgdocs/postgres/protocol-flow.html#PROTOCOL-FLOW-EXT-QUERY
203203
connection.bind({
204-
portal: self.portalName,
204+
portal: self.portal,
205205
statement: self.name,
206206
values: self.values,
207207
binary: self.binary
208208
}, true)
209209

210210
connection.describe({
211211
type: 'P',
212-
name: self.portalName || ''
212+
name: self.portal || ''
213213
}, true)
214214

215215
this._getRows(connection, this.rows)

test/unit/client/prepared-statement-tests.js

+69-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ test('bound command', function () {
6565

6666
test('bind argument', function () {
6767
assert.equal(bindArg.statement, null)
68-
assert.equal(bindArg.portal, null)
68+
assert.equal(bindArg.portal, '')
6969
assert.lengthIs(bindArg.values, 1)
7070
assert.equal(bindArg.values[0], 'hi')
7171
})
@@ -76,7 +76,7 @@ test('bound command', function () {
7676
})
7777

7878
test('execute argument', function () {
79-
assert.equal(executeArg.portal, null)
79+
assert.equal(executeArg.portal, '')
8080
assert.equal(executeArg.rows, null)
8181
})
8282

@@ -86,3 +86,70 @@ test('bound command', function () {
8686
})
8787
})
8888
})
89+
90+
var portalClient = helper.client()
91+
var portalCon = portalClient.connection
92+
var portalParseArg = null
93+
portalCon.parse = function (arg) {
94+
portalParseArg = arg
95+
process.nextTick(function () {
96+
portalCon.emit('parseComplete')
97+
})
98+
}
99+
100+
var portalBindArg = null
101+
portalCon.bind = function (arg) {
102+
portalBindArg = arg
103+
process.nextTick(function () {
104+
portalCon.emit('bindComplete')
105+
})
106+
}
107+
108+
var portalExecuteArg = null
109+
portalCon.execute = function (arg) {
110+
portalExecuteArg = arg
111+
process.nextTick(function () {
112+
portalCon.emit('rowData', { fields: [] })
113+
portalCon.emit('commandComplete', { text: '' })
114+
})
115+
}
116+
117+
var portalDescribeArg = null
118+
portalCon.describe = function (arg) {
119+
portalDescribeArg = arg
120+
process.nextTick(function () {
121+
portalCon.emit('rowDescription', { fields: [] })
122+
})
123+
}
124+
125+
portalCon.flush = function () {
126+
}
127+
portalCon.sync = function () {
128+
process.nextTick(function () {
129+
portalCon.emit('readyForQuery')
130+
})
131+
}
132+
133+
test('prepared statement with explicit portal', function () {
134+
assert.ok(portalClient.connection.emit('readyForQuery'))
135+
136+
var query = portalClient.query(new Query({
137+
text: 'select * from X where name = $1',
138+
portal: 'myportal',
139+
values: ['hi']
140+
}))
141+
142+
assert.emits(query, 'end', function () {
143+
test('bind argument', function () {
144+
assert.equal(portalBindArg.portal, 'myportal')
145+
})
146+
147+
test('describe argument', function () {
148+
assert.equal(portalDescribeArg.name, 'myportal')
149+
})
150+
151+
test('execute argument', function () {
152+
assert.equal(portalExecuteArg.portal, 'myportal')
153+
})
154+
})
155+
})

0 commit comments

Comments
 (0)