File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -310,6 +310,10 @@ impl<'conn> Statement<'conn> {
310
310
311
311
let ( format, column_formats) = match try!( conn. read_message ( ) ) {
312
312
CopyInResponse { format, column_formats } => ( format, column_formats) ,
313
+ ErrorResponse { fields } => {
314
+ try!( conn. wait_for_ready ( ) ) ;
315
+ return DbError :: new ( fields) ;
316
+ }
313
317
_ => {
314
318
loop {
315
319
match try!( conn. read_message ( ) ) {
@@ -425,6 +429,10 @@ impl<'conn> Statement<'conn> {
425
429
io:: ErrorKind :: InvalidInput ,
426
430
"called `copy_out` on a non-`COPY TO STDOUT` statement" ) ) ) ;
427
431
}
432
+ ErrorResponse { fields } => {
433
+ try!( conn. wait_for_ready ( ) ) ;
434
+ return DbError :: new ( fields) ;
435
+ }
428
436
_ => {
429
437
loop {
430
438
match try!( conn. read_message ( ) ) {
Original file line number Diff line number Diff line change @@ -811,6 +811,21 @@ fn test_copy_out() {
811
811
or_panic ! ( conn. batch_execute( "SELECT 1" ) ) ;
812
812
}
813
813
814
+ #[ test]
815
+ fn test_copy_out_error ( ) {
816
+ let conn = or_panic ! ( Connection :: connect( "postgres://postgres@localhost" , & SslMode :: None ) ) ;
817
+ or_panic ! ( conn. batch_execute( "
818
+ CREATE TEMPORARY TABLE foo (id INT);
819
+ INSERT INTO foo (id) VALUES (0), (1), (2), (3)" ) ) ;
820
+ let stmt = or_panic ! ( conn. prepare( "COPY (SELECT id FROM foo ORDER BY id) TO STDOUT (OIDS)" ) ) ;
821
+ let mut buf = vec ! [ ] ;
822
+ match stmt. copy_out ( & [ ] , & mut buf) {
823
+ Ok ( _) => panic ! ( "unexpected success" ) ,
824
+ Err ( Error :: DbError ( ..) ) => { }
825
+ Err ( e) => panic ! ( "unexpected error {}" , e) ,
826
+ }
827
+ }
828
+
814
829
#[ test]
815
830
// Just make sure the impls don't infinite loop
816
831
fn test_generic_connection ( ) {
You can’t perform that action at this time.
0 commit comments