@@ -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