diff --git a/lib/query.js b/lib/query.js index 4d483ac7..8766e1a3 100644 --- a/lib/query.js +++ b/lib/query.js @@ -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) diff --git a/test/unit/client/prepared-statement-tests.js b/test/unit/client/prepared-statement-tests.js index 0dc9e80a..08db8860 100644 --- a/test/unit/client/prepared-statement-tests.js +++ b/test/unit/client/prepared-statement-tests.js @@ -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') + }) + }) +})