@@ -42,6 +42,7 @@ struct InnerConnection {
42
42
stream : PostgresStream ,
43
43
parameters : HashMap < String , String > ,
44
44
cancel_data : CancelData ,
45
+ next_stmt_id : u32 ,
45
46
}
46
47
47
48
impl InnerConnection {
@@ -127,7 +128,8 @@ impl Connection {
127
128
cancel_data : CancelData {
128
129
process_id : 0 ,
129
130
secret_key : 0 ,
130
- }
131
+ } ,
132
+ next_stmt_id : 0 ,
131
133
} )
132
134
} )
133
135
. and_then ( |s| s. startup ( params) )
@@ -402,8 +404,6 @@ impl Connection {
402
404
|f, t| Column { name : f. 0 , type_ : t } )
403
405
. map ( |( r, s) | ( p, r, s) )
404
406
} )
405
- . and_then ( |( p, r, s) | s. ready ( ( p, r) ) )
406
- . map ( |( ( p, r) , s) | ( p, r, s) )
407
407
. boxed ( )
408
408
}
409
409
@@ -454,8 +454,8 @@ impl Connection {
454
454
let mut bind = vec ! [ ] ;
455
455
let mut execute = vec ! [ ] ;
456
456
let mut sync = vec ! [ ] ;
457
- let r = frontend:: bind ( stmt ,
458
- portal ,
457
+ let r = frontend:: bind ( portal ,
458
+ stmt ,
459
459
Some ( 1 ) ,
460
460
params. iter ( ) . zip ( param_types) ,
461
461
|( param, ty) , buf| {
@@ -533,6 +533,22 @@ impl Connection {
533
533
. boxed ( )
534
534
}
535
535
536
+ pub fn prepare ( mut self , query : & str ) -> BoxFuture < ( Statement , Connection ) , Error > {
537
+ let id = self . 0 . next_stmt_id ;
538
+ self . 0 . next_stmt_id += 1 ;
539
+ let name = format ! ( "s{}" , id) ;
540
+ self . raw_prepare ( & name, query)
541
+ . map ( |( params, columns, conn) | {
542
+ let stmt = Statement {
543
+ name : name,
544
+ params : params,
545
+ columns : columns,
546
+ } ;
547
+ ( stmt, conn)
548
+ } )
549
+ . boxed ( )
550
+ }
551
+
536
552
pub fn cancel_data ( & self ) -> CancelData {
537
553
self . 0 . cancel_data
538
554
}
@@ -543,6 +559,24 @@ struct Column {
543
559
type_ : Type ,
544
560
}
545
561
562
+ pub struct Statement {
563
+ name : String ,
564
+ params : Vec < Type > ,
565
+ columns : Vec < Column > ,
566
+ }
567
+
568
+ impl Statement {
569
+ pub fn execute ( self ,
570
+ params : & [ & ToSql ] ,
571
+ conn : Connection )
572
+ -> BoxFuture < ( u64 , Statement , Connection ) , Error > {
573
+ conn. raw_execute ( & self . name , "" , & self . params , params)
574
+ . and_then ( |conn| conn. finish_execute ( ) )
575
+ . map ( |( n, conn) | ( n, self , conn) )
576
+ . boxed ( )
577
+ }
578
+ }
579
+
546
580
fn connect_err ( fields : & mut ErrorFields ) -> ConnectError {
547
581
match DbError :: new ( fields) {
548
582
Ok ( err) => ConnectError :: Db ( Box :: new ( err) ) ,
0 commit comments