@@ -8,6 +8,7 @@ use std::collections::HashMap;
88use std:: error:: Error as StdError ;
99use std:: sync:: { Arc , Weak } ;
1010
11+ use proto:: bind:: BindFuture ;
1112use proto:: connection:: { Request , RequestMessages } ;
1213use proto:: copy_in:: { CopyInFuture , CopyInReceiver , CopyMessage } ;
1314use proto:: copy_out:: CopyOutStream ;
@@ -140,6 +141,15 @@ impl Client {
140141 QueryStream :: new ( self . clone ( ) , pending, statement. clone ( ) )
141142 }
142143
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+
143153 pub fn copy_in < S > ( & self , statement : & Statement , params : & [ & ToSql ] , stream : S ) -> CopyInFuture < S >
144154 where
145155 S : Stream ,
@@ -169,8 +179,16 @@ impl Client {
169179 }
170180
171181 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 ) {
172190 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" ) ;
174192 frontend:: sync ( & mut buf) ;
175193 let ( sender, _) = mpsc:: channel ( 0 ) ;
176194 let _ = self . 0 . sender . unbounded_send ( Request {
@@ -179,10 +197,15 @@ impl Client {
179197 } ) ;
180198 }
181199
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 > {
183206 let mut buf = vec ! [ ] ;
184207 let r = frontend:: bind (
185- "" ,
208+ name ,
186209 statement. name ( ) ,
187210 Some ( 1 ) ,
188211 params. iter ( ) . zip ( statement. params ( ) ) ,
@@ -195,10 +218,14 @@ impl Client {
195218 & mut buf,
196219 ) ;
197220 match r {
198- Ok ( ( ) ) => { }
221+ Ok ( ( ) ) => Ok ( buf ) ,
199222 Err ( frontend:: BindError :: Conversion ( e) ) => return Err ( Error :: to_sql ( e) ) ,
200223 Err ( frontend:: BindError :: Serialization ( e) ) => return Err ( Error :: encode ( e) ) ,
201224 }
225+ }
226+
227+ fn excecute_message ( & self , statement : & Statement , params : & [ & ToSql ] ) -> Result < Vec < u8 > , Error > {
228+ let mut buf = self . bind_message ( statement, "" , params) ?;
202229 frontend:: execute ( "" , 0 , & mut buf) . map_err ( Error :: parse) ?;
203230 frontend:: sync ( & mut buf) ;
204231 Ok ( buf)
0 commit comments