Skip to content

Fix commit-time error reporting #833

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions tokio-postgres/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,22 @@ where
};
let mut responses = start(client, buf).await?;

let mut rows = 0;
loop {
match responses.next().await? {
Message::DataRow(_) => {}
Message::CommandComplete(body) => {
let rows = body
rows = body
.tag()
.map_err(Error::parse)?
.rsplit(' ')
.next()
.unwrap()
.parse()
.unwrap_or(0);
return Ok(rows);
}
Message::EmptyQueryResponse => return Ok(0),
Message::EmptyQueryResponse => rows = 0,
Message::ReadyForQuery(_) => return Ok(rows),
_ => return Err(Error::unexpected_message()),
}
}
Expand Down Expand Up @@ -203,15 +204,17 @@ impl Stream for RowStream {

fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
let this = self.project();
match ready!(this.responses.poll_next(cx)?) {
Message::DataRow(body) => {
Poll::Ready(Some(Ok(Row::new(this.statement.clone(), body)?)))
loop {
match ready!(this.responses.poll_next(cx)?) {
Message::DataRow(body) => {
return Poll::Ready(Some(Ok(Row::new(this.statement.clone(), body)?)))
}
Message::EmptyQueryResponse
| Message::CommandComplete(_)
| Message::PortalSuspended => {}
Message::ReadyForQuery(_) => return Poll::Ready(None),
_ => return Poll::Ready(Some(Err(Error::unexpected_message()))),
}
Message::EmptyQueryResponse
| Message::CommandComplete(_)
| Message::PortalSuspended => Poll::Ready(None),
Message::ErrorResponse(body) => Poll::Ready(Some(Err(Error::db(body)))),
_ => Poll::Ready(Some(Err(Error::unexpected_message()))),
}
}
}
26 changes: 26 additions & 0 deletions tokio-postgres/tests/test/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -805,3 +805,29 @@ async fn query_opt() {
.err()
.unwrap();
}

#[tokio::test]
async fn deferred_constraint() {
let client = connect("user=postgres").await;

client
.batch_execute(
"
CREATE TEMPORARY TABLE t (
i INT,
UNIQUE (i) DEFERRABLE INITIALLY DEFERRED
);
",
)
.await
.unwrap();

client
.execute("INSERT INTO t (i) VALUES (1)", &[])
.await
.unwrap();
client
.execute("INSERT INTO t (i) VALUES (1)", &[])
.await
.unwrap_err();
}