Skip to content

Commit

Permalink
Merge pull request #1165 from exograph/query-typed-no-data
Browse files Browse the repository at this point in the history
For `query_typed`, deal with the no-data case.
  • Loading branch information
sfackler authored Jul 23, 2024
2 parents 9f196e7 + 0fc4005 commit 3afcc3d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
13 changes: 9 additions & 4 deletions tokio-postgres/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,15 @@ where

loop {
match responses.next().await? {
Message::ParseComplete
| Message::BindComplete
| Message::ParameterDescription(_)
| Message::NoData => {}
Message::ParseComplete | Message::BindComplete | Message::ParameterDescription(_) => {}
Message::NoData => {
return Ok(RowStream {
statement: Statement::unnamed(vec![], vec![]),
responses,
rows_affected: None,
_p: PhantomPinned,
});
}
Message::RowDescription(row_description) => {
let mut columns: Vec<Column> = vec![];
let mut it = row_description.fields();
Expand Down
14 changes: 14 additions & 0 deletions tokio-postgres/tests/test/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,13 @@ async fn query_typed_no_transaction() {
assert_eq!(second_row.get::<_, i32>(1), 40);
assert_eq!(second_row.get::<_, &str>(2), "literal");
assert_eq!(second_row.get::<_, i32>(3), 5);

// Test for UPDATE that returns no data
let updated_rows = client
.query_typed("UPDATE foo set age = 33", &[])
.await
.unwrap();
assert_eq!(updated_rows.len(), 0);
}

#[tokio::test]
Expand Down Expand Up @@ -1064,4 +1071,11 @@ async fn query_typed_with_transaction() {
assert_eq!(second_row.get::<_, i32>(1), 40);
assert_eq!(second_row.get::<_, &str>(2), "literal");
assert_eq!(second_row.get::<_, i32>(3), 5);

// Test for UPDATE that returns no data
let updated_rows = transaction
.query_typed("UPDATE foo set age = 33", &[])
.await
.unwrap();
assert_eq!(updated_rows.len(), 0);
}

0 comments on commit 3afcc3d

Please sign in to comment.