File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1693,6 +1693,18 @@ impl<'stmt> Row<'stmt> {
16931693 Err ( err) => panic ! ( "error retrieving column {:?}: {:?}" , idx, err)
16941694 }
16951695 }
1696+
1697+ /// Retrieves the specified field as a raw buffer of Postgres data.
1698+ ///
1699+ /// ## Panics
1700+ ///
1701+ /// Panics if the index does not references a column.
1702+ pub fn get_bytes < I > ( & self , idx : I ) -> Option < & [ u8 ] > where I : RowIndex + fmt:: Debug {
1703+ match idx. idx ( self . stmt ) {
1704+ Some ( idx) => self . data [ idx] . as_ref ( ) . map ( |e| & * * e) ,
1705+ None => panic ! ( "invalid index {:?}" , idx) ,
1706+ }
1707+ }
16961708}
16971709
16981710/// A trait implemented by types that can index into columns of a row.
Original file line number Diff line number Diff line change @@ -917,3 +917,11 @@ fn test_parameter() {
917917 assert_eq ! ( Some ( "UTF8" . to_string( ) ) , conn. parameter( "client_encoding" ) ) ;
918918 assert_eq ! ( None , conn. parameter( "asdf" ) ) ;
919919}
920+
921+ #[ test]
922+ fn test_get_bytes ( ) {
923+ let conn = or_panic ! ( Connection :: connect( "postgres://postgres@localhost" , & SslMode :: None ) ) ;
924+ let stmt = or_panic ! ( conn. prepare( "SELECT '\\ x00010203'::BYTEA" ) ) ;
925+ let mut result = or_panic ! ( stmt. query( & [ ] ) ) ;
926+ assert_eq ! ( b"\x00 \x01 \x02 \x03 " , result. next( ) . unwrap( ) . get_bytes( 0 ) . unwrap( ) ) ;
927+ }
You can’t perform that action at this time.
0 commit comments