Skip to content

Commit cdaab78

Browse files
committed
Merge pull request rust-postgres#49 from johto/errorresponse_after_datarow
Correctly handle ErrorResponse after one or more DataRows
2 parents a2c597e + b95299e commit cdaab78

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

src/lib/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff 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);

src/test/test.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ use postgres::error::{PgConnectDbError,
3939
QueryCanceled,
4040
UndefinedTable,
4141
InvalidCatalogName,
42-
PgWrongTransaction};
42+
PgWrongTransaction,
43+
CardinalityViolation};
4344
use postgres::types::{ToSql, FromSql, PgInt4, PgVarchar};
4445
use postgres::types::array::{ArrayBase};
4546
use 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(0u)).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]
365383
fn test_result_finish() {
366384
let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl));

0 commit comments

Comments
 (0)