@@ -8,6 +8,7 @@ use std::collections::HashMap;
8
8
use std:: error:: Error as StdError ;
9
9
use std:: sync:: { Arc , Weak } ;
10
10
11
+ use proto:: bind:: BindFuture ;
11
12
use proto:: connection:: { Request , RequestMessages } ;
12
13
use proto:: copy_in:: { CopyInFuture , CopyInReceiver , CopyMessage } ;
13
14
use proto:: copy_out:: CopyOutStream ;
@@ -140,6 +141,15 @@ impl Client {
140
141
QueryStream :: new ( self . clone ( ) , pending, statement. clone ( ) )
141
142
}
142
143
144
+ pub fn bind ( & self , statement : & Statement , name : String , params : & [ & ToSql ] ) -> BindFuture {
145
+ let mut buf = self . bind_message ( statement, & name, params) ;
146
+ if let Ok ( ref mut buf) = buf {
147
+ frontend:: sync ( buf) ;
148
+ }
149
+ let pending = PendingRequest ( buf. map ( RequestMessages :: Single ) ) ;
150
+ BindFuture :: new ( self . clone ( ) , pending, name, statement. clone ( ) )
151
+ }
152
+
143
153
pub fn copy_in < S > ( & self , statement : & Statement , params : & [ & ToSql ] , stream : S ) -> CopyInFuture < S >
144
154
where
145
155
S : Stream ,
@@ -169,8 +179,16 @@ impl Client {
169
179
}
170
180
171
181
pub fn close_statement ( & self , name : & str ) {
182
+ self . close ( b'S' , name)
183
+ }
184
+
185
+ pub fn close_portal ( & self , name : & str ) {
186
+ self . close ( b'P' , name)
187
+ }
188
+
189
+ fn close ( & self , ty : u8 , name : & str ) {
172
190
let mut buf = vec ! [ ] ;
173
- frontend:: close ( b'S' , name, & mut buf) . expect ( "statement name not valid" ) ;
191
+ frontend:: close ( ty , name, & mut buf) . expect ( "statement name not valid" ) ;
174
192
frontend:: sync ( & mut buf) ;
175
193
let ( sender, _) = mpsc:: channel ( 0 ) ;
176
194
let _ = self . 0 . sender . unbounded_send ( Request {
@@ -179,10 +197,15 @@ impl Client {
179
197
} ) ;
180
198
}
181
199
182
- fn excecute_message ( & self , statement : & Statement , params : & [ & ToSql ] ) -> Result < Vec < u8 > , Error > {
200
+ fn bind_message (
201
+ & self ,
202
+ statement : & Statement ,
203
+ name : & str ,
204
+ params : & [ & ToSql ] ,
205
+ ) -> Result < Vec < u8 > , Error > {
183
206
let mut buf = vec ! [ ] ;
184
207
let r = frontend:: bind (
185
- "" ,
208
+ name ,
186
209
statement. name ( ) ,
187
210
Some ( 1 ) ,
188
211
params. iter ( ) . zip ( statement. params ( ) ) ,
@@ -195,10 +218,14 @@ impl Client {
195
218
& mut buf,
196
219
) ;
197
220
match r {
198
- Ok ( ( ) ) => { }
221
+ Ok ( ( ) ) => Ok ( buf ) ,
199
222
Err ( frontend:: BindError :: Conversion ( e) ) => return Err ( Error :: to_sql ( e) ) ,
200
223
Err ( frontend:: BindError :: Serialization ( e) ) => return Err ( Error :: encode ( e) ) ,
201
224
}
225
+ }
226
+
227
+ fn excecute_message ( & self , statement : & Statement , params : & [ & ToSql ] ) -> Result < Vec < u8 > , Error > {
228
+ let mut buf = self . bind_message ( statement, "" , params) ?;
202
229
frontend:: execute ( "" , 0 , & mut buf) . map_err ( Error :: parse) ?;
203
230
frontend:: sync ( & mut buf) ;
204
231
Ok ( buf)
0 commit comments