@@ -72,7 +72,6 @@ use openssl::ssl::SslContext;
7272use serialize:: hex:: ToHex ;
7373use std:: cell:: { Cell , RefCell } ;
7474use std:: collections:: HashMap ;
75- use std:: from_str:: FromStr ;
7675use std:: io:: { BufferedStream , IoResult , MemWriter } ;
7776use std:: io:: net:: ip:: Port ;
7877use std:: mem;
@@ -614,7 +613,6 @@ impl InnerPostgresConnection {
614613 conn : conn,
615614 name : stmt_name,
616615 column_types : column_types,
617- next_portal_id : Cell :: new ( 0 ) ,
618616 finished : false ,
619617 } )
620618 }
@@ -1256,8 +1254,7 @@ impl<'conn> PostgresStatement<'conn> {
12561254 return Err ( PgDbError ( PostgresDbError :: new ( fields) ) ) ;
12571255 }
12581256 CommandComplete { tag } => {
1259- let s = tag. as_slice ( ) . split ( ' ' ) . last ( ) . unwrap ( ) ;
1260- num = FromStr :: from_str ( s) . unwrap_or ( 0 ) ;
1257+ num = util:: parse_update_count ( tag) ;
12611258 break ;
12621259 }
12631260 EmptyQueryResponse => {
@@ -1568,11 +1565,11 @@ impl<'trans, 'stmt> Iterator<PostgresResult<PostgresRow<'stmt>>>
15681565 }
15691566}
15701567
1568+ /// A prepared COPY FROM STDIN statement
15711569pub struct PostgresCopyInStatement < ' a > {
15721570 conn : & ' a PostgresConnection ,
15731571 name : String ,
15741572 column_types : Vec < PostgresType > ,
1575- next_portal_id : Cell < uint > ,
15761573 finished : bool ,
15771574}
15781575
@@ -1592,7 +1589,13 @@ impl<'a> PostgresCopyInStatement<'a> {
15921589 conn. close_statement ( self . name . as_slice ( ) )
15931590 }
15941591
1595- pub fn execute < ' b , I , J > ( & self , mut rows : I ) -> PostgresResult < ( ) >
1592+ /// Executes the prepared statement.
1593+ ///
1594+ /// Each iterator retuned by the `rows` iterator will be interpreted as
1595+ /// providing a single result row.
1596+ ///
1597+ /// Returns the number of rows copied.
1598+ pub fn execute < ' b , I , J > ( & self , mut rows : I ) -> PostgresResult < uint >
15961599 where I : Iterator < J > , J : Iterator < & ' b ToSql + ' b > {
15971600 let mut conn = self . conn . conn . borrow_mut ( ) ;
15981601
@@ -1680,8 +1683,8 @@ impl<'a> PostgresCopyInStatement<'a> {
16801683 try_pg ! ( conn. stream. write_message( & Sync ) ) ;
16811684 try_pg ! ( conn. stream. flush( ) ) ;
16821685
1683- match try_pg ! ( conn. read_message_( ) ) {
1684- CommandComplete { .. } => { } ,
1686+ let num = match try_pg ! ( conn. read_message_( ) ) {
1687+ CommandComplete { tag } => util :: parse_update_count ( tag ) ,
16851688 ErrorResponse { fields } => {
16861689 try!( conn. wait_for_ready ( ) ) ;
16871690 return Err ( PgDbError ( PostgresDbError :: new ( fields) ) ) ;
@@ -1690,9 +1693,10 @@ impl<'a> PostgresCopyInStatement<'a> {
16901693 conn. desynchronized = true ;
16911694 return Err ( PgBadResponse ) ;
16921695 }
1693- }
1696+ } ;
16941697
1695- conn. wait_for_ready ( )
1698+ try!( conn. wait_for_ready ( ) ) ;
1699+ Ok ( num)
16961700 }
16971701
16981702 /// Consumes the statement, clearing it from the Postgres session.
0 commit comments