@@ -908,17 +908,33 @@ impl Connection {
908908 InnerConnection :: connect ( params, ssl) . map ( |conn| Connection { conn : RefCell :: new ( conn) } )
909909 }
910910
911- /// A convenience function for queries that are only run once .
911+ /// Executes a statement, returning the number of rows modified .
912912 ///
913- /// If an error is returned, it could have come from either the preparation
914- /// or execution of the statement.
913+ /// A statement may contain parameters, specified by `$n` where `n` is the
914+ /// index of the parameter in the list provided, 1-indexed.
915+ ///
916+ /// If the statement does not modify any rows (e.g. SELECT), 0 is returned.
915917 ///
916- /// On success, returns the number of rows modified or 0 if not applicable.
918+ /// If the same statement will be repeatedly executed (perhaps with
919+ /// different query parameters), consider using the `prepare` and
920+ /// `prepare_cached` methods.
917921 ///
918922 /// # Panics
919923 ///
920924 /// Panics if the number of parameters provided does not match the number
921925 /// expected.
926+ ///
927+ /// # Example
928+ ///
929+ /// ```rust,no_run
930+ /// # use postgres::{Connection, SslMode};
931+ /// # let conn = Connection::connect("", SslMode::None).unwrap();
932+ /// # let bar = 1i32;
933+ /// # let baz = true;
934+ /// let rows_updated = conn.execute("UPDATE foo SET bar = $1 WHERE baz = $2", &[&bar, &baz])
935+ /// .unwrap();
936+ /// println!("{} rows updated", rows_updated);
937+ /// ```
922938 pub fn execute ( & self , query : & str , params : & [ & ToSql ] ) -> Result < u64 > {
923939 let ( param_types, columns) = try!( self . conn . borrow_mut ( ) . raw_prepare ( "" , query) ) ;
924940 let stmt = Statement :: new ( self ,
@@ -930,17 +946,31 @@ impl Connection {
930946 stmt. execute ( params)
931947 }
932948
933- /// A convenience function for queries that are only run once .
949+ /// Executes a statement, returning the resulting rows .
934950 ///
935- /// If an error is returned, it could have come from either the preparation
936- /// or execution of the statement .
951+ /// A statement may contain parameters, specified by `$n` where `n` is the
952+ /// index of the parameter in the list provided, 1-indexed .
937953 ///
938- /// On success, returns the resulting rows.
954+ /// If the same statement will be repeatedly executed (perhaps with
955+ /// different query parameters), consider using the `prepare` and
956+ /// `prepare_cached` methods.
939957 ///
940- /// ## Panics
958+ /// # Panics
941959 ///
942960 /// Panics if the number of parameters provided does not match the number
943961 /// expected.
962+ ///
963+ /// # Example
964+ ///
965+ /// ```rust,no_run
966+ /// # use postgres::{Connection, SslMode};
967+ /// # let conn = Connection::connect("", SslMode::None).unwrap();
968+ /// # let baz = true;
969+ /// for row in &conn.query("SELECT foo FROM bar WHERE baz = $1", &[&baz]).unwrap() {
970+ /// let foo: i32 = row.get("foo");
971+ /// println!("foo: {}", foo);
972+ /// }
973+ /// ```
944974 pub fn query < ' a > ( & ' a self , query : & str , params : & [ & ToSql ] ) -> Result < Rows < ' a > > {
945975 let ( param_types, columns) = try!( self . conn . borrow_mut ( ) . raw_prepare ( "" , query) ) ;
946976 let stmt = Statement :: new ( self , "" . to_owned ( ) , param_types, columns, Cell :: new ( 0 ) , true ) ;
@@ -989,9 +1019,8 @@ impl Connection {
9891019
9901020 /// Creates a new prepared statement.
9911021 ///
992- /// A statement may contain parameters, specified by `$n` where `n` is the
993- /// index of the parameter in the list provided at execution time,
994- /// 1-indexed.
1022+ /// If the same statement will be executed repeatedly, explicitly preparing
1023+ /// it can improve performance.
9951024 ///
9961025 /// The statement is associated with the connection that created it and may
9971026 /// not outlive that connection.
@@ -1016,8 +1045,8 @@ impl Connection {
10161045 ///
10171046 /// Like `prepare`, except that the statement is only prepared once over
10181047 /// the lifetime of the connection and then cached. If the same statement
1019- /// is going to be used frequently, caching it can improve performance by
1020- /// reducing the number of round trips to the Postgres backend.
1048+ /// is going to be prepared frequently, caching it can improve performance
1049+ /// by reducing the number of round trips to the Postgres backend.
10211050 ///
10221051 /// # Example
10231052 ///
0 commit comments