File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1316,6 +1316,10 @@ impl<'stmt> PostgresRows<'stmt> {
13161316 break ;
13171317 } ,
13181318 DataRow { row } => self . data . push_back ( row) ,
1319+ ErrorResponse { fields } => {
1320+ try!( self . stmt . conn . wait_for_ready ( ) ) ;
1321+ return Err ( PgDbError ( PostgresDbError :: new ( fields) ) ) ;
1322+ }
13191323 _ => {
13201324 self . stmt . conn . conn . borrow_mut ( ) . desynchronized = true ;
13211325 return Err ( PgBadResponse ) ;
Original file line number Diff line number Diff line change @@ -39,7 +39,8 @@ use postgres::error::{PgConnectDbError,
3939 QueryCanceled ,
4040 UndefinedTable ,
4141 InvalidCatalogName ,
42- PgWrongTransaction } ;
42+ PgWrongTransaction ,
43+ CardinalityViolation } ;
4344use postgres:: types:: { ToSql , FromSql , PgInt4 , PgVarchar } ;
4445use postgres:: types:: array:: { ArrayBase } ;
4546use postgres:: types:: range:: { Range , Inclusive , Exclusive , RangeBound } ;
@@ -361,6 +362,23 @@ fn test_query() {
361362 assert_eq ! ( vec![ 1i64 , 2 ] , result. map( |row| row. get( 0 u) ) . collect( ) ) ;
362363}
363364
365+ #[ test]
366+ fn test_error_after_datarow ( ) {
367+ let conn = or_fail ! ( PostgresConnection :: connect( "postgres://postgres@localhost" , & NoSsl ) ) ;
368+ let stmt = or_fail ! ( conn. prepare( "
369+ SELECT
370+ (SELECT generate_series(1, ss.i))
371+ FROM (SELECT gs.i
372+ FROM generate_series(1, 2) gs(i)
373+ ORDER BY gs.i
374+ LIMIT 2) ss" ) ) ;
375+ match stmt. query ( [ ] ) {
376+ Err ( PgDbError ( PostgresDbError { code : CardinalityViolation , .. } ) ) => { }
377+ Err ( err) => fail ! ( "Unexpected error {}" , err) ,
378+ Ok ( _) => fail ! ( "Expected failure" ) ,
379+ }
380+ }
381+
364382#[ test]
365383fn test_result_finish ( ) {
366384 let conn = or_fail ! ( PostgresConnection :: connect( "postgres://postgres@localhost" , & NoSsl ) ) ;
You can’t perform that action at this time.
0 commit comments