mirror of
https://github.com/brianc/node-postgres.git
synced 2026-01-18 15:55:05 +00:00
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`.
This commit is contained in:
parent
9389527609
commit
831dfb1b4c
@ -175,7 +175,7 @@ Query.prototype.handlePortalSuspended = function (connection) {
|
||||
|
||||
Query.prototype._getRows = function (connection, rows) {
|
||||
connection.execute({
|
||||
portal: this.portalName,
|
||||
portal: this.portal,
|
||||
rows: rows
|
||||
}, true)
|
||||
connection.flush()
|
||||
@ -201,7 +201,7 @@ Query.prototype.prepare = function (connection) {
|
||||
|
||||
// http://developer.postgresql.org/pgdocs/postgres/protocol-flow.html#PROTOCOL-FLOW-EXT-QUERY
|
||||
connection.bind({
|
||||
portal: self.portalName,
|
||||
portal: self.portal,
|
||||
statement: self.name,
|
||||
values: self.values,
|
||||
binary: self.binary
|
||||
@ -209,7 +209,7 @@ Query.prototype.prepare = function (connection) {
|
||||
|
||||
connection.describe({
|
||||
type: 'P',
|
||||
name: self.portalName || ''
|
||||
name: self.portal || ''
|
||||
}, true)
|
||||
|
||||
this._getRows(connection, this.rows)
|
||||
|
||||
@ -65,7 +65,7 @@ test('bound command', function () {
|
||||
|
||||
test('bind argument', function () {
|
||||
assert.equal(bindArg.statement, null)
|
||||
assert.equal(bindArg.portal, null)
|
||||
assert.equal(bindArg.portal, '')
|
||||
assert.lengthIs(bindArg.values, 1)
|
||||
assert.equal(bindArg.values[0], 'hi')
|
||||
})
|
||||
@ -76,7 +76,7 @@ test('bound command', function () {
|
||||
})
|
||||
|
||||
test('execute argument', function () {
|
||||
assert.equal(executeArg.portal, null)
|
||||
assert.equal(executeArg.portal, '')
|
||||
assert.equal(executeArg.rows, null)
|
||||
})
|
||||
|
||||
@ -86,3 +86,70 @@ test('bound command', function () {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
var portalClient = helper.client()
|
||||
var portalCon = portalClient.connection
|
||||
var portalParseArg = null
|
||||
portalCon.parse = function (arg) {
|
||||
portalParseArg = arg
|
||||
process.nextTick(function () {
|
||||
portalCon.emit('parseComplete')
|
||||
})
|
||||
}
|
||||
|
||||
var portalBindArg = null
|
||||
portalCon.bind = function (arg) {
|
||||
portalBindArg = arg
|
||||
process.nextTick(function () {
|
||||
portalCon.emit('bindComplete')
|
||||
})
|
||||
}
|
||||
|
||||
var portalExecuteArg = null
|
||||
portalCon.execute = function (arg) {
|
||||
portalExecuteArg = arg
|
||||
process.nextTick(function () {
|
||||
portalCon.emit('rowData', { fields: [] })
|
||||
portalCon.emit('commandComplete', { text: '' })
|
||||
})
|
||||
}
|
||||
|
||||
var portalDescribeArg = null
|
||||
portalCon.describe = function (arg) {
|
||||
portalDescribeArg = arg
|
||||
process.nextTick(function () {
|
||||
portalCon.emit('rowDescription', { fields: [] })
|
||||
})
|
||||
}
|
||||
|
||||
portalCon.flush = function () {
|
||||
}
|
||||
portalCon.sync = function () {
|
||||
process.nextTick(function () {
|
||||
portalCon.emit('readyForQuery')
|
||||
})
|
||||
}
|
||||
|
||||
test('prepared statement with explicit portal', function () {
|
||||
assert.ok(portalClient.connection.emit('readyForQuery'))
|
||||
|
||||
var query = portalClient.query(new Query({
|
||||
text: 'select * from X where name = $1',
|
||||
portal: 'myportal',
|
||||
values: ['hi']
|
||||
}))
|
||||
|
||||
assert.emits(query, 'end', function () {
|
||||
test('bind argument', function () {
|
||||
assert.equal(portalBindArg.portal, 'myportal')
|
||||
})
|
||||
|
||||
test('describe argument', function () {
|
||||
assert.equal(portalDescribeArg.name, 'myportal')
|
||||
})
|
||||
|
||||
test('execute argument', function () {
|
||||
assert.equal(portalExecuteArg.portal, 'myportal')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user