Skip to content

Commit 3809972

Browse files
committed
Fix execute of statements which return rows
Closes #274
1 parent ed17d5e commit 3809972

File tree

2 files changed

+29
-20
lines changed

2 files changed

+29
-20
lines changed

tokio-postgres/src/lib.rs

+20-20
Original file line numberDiff line numberDiff line change
@@ -901,28 +901,28 @@ impl Connection {
901901
self.0
902902
.read()
903903
.map_err(Error::Io)
904-
.and_then(|(m, s)| match m {
905-
backend::Message::DataRow(_) => Either::B(Connection(s).finish_execute()),
906-
backend::Message::CommandComplete(body) => {
907-
Either::A(body.tag()
908-
.map(|tag| {
909-
let num = tag.split_whitespace()
910-
.last()
911-
.unwrap()
912-
.parse()
913-
.unwrap_or(0);
914-
(num, Connection(s))
915-
})
916-
.map_err(Error::Io)
917-
.into_future())
918-
}
919-
backend::Message::EmptyQueryResponse => {
920-
Either::A(Ok((0, Connection(s))).into_future())
904+
.and_then(|(m, s)| {
905+
match m {
906+
backend::Message::DataRow(_) => Connection(s).finish_execute().boxed(),
907+
backend::Message::CommandComplete(body) => {
908+
body.tag()
909+
.map(|tag| {
910+
tag.split_whitespace()
911+
.last()
912+
.unwrap()
913+
.parse()
914+
.unwrap_or(0)
915+
})
916+
.map_err(Error::Io)
917+
.into_future()
918+
.and_then(|n| Connection(s).ready(n))
919+
.boxed()
920+
}
921+
backend::Message::EmptyQueryResponse => Connection(s).ready(0).boxed(),
922+
backend::Message::ErrorResponse(body) => Connection(s).ready_err(body).boxed(),
923+
_ => Err(bad_message()).into_future().boxed(),
921924
}
922-
backend::Message::ErrorResponse(body) => Either::B(Connection(s).ready_err(body)),
923-
_ => Either::A(Err(bad_message()).into_future()),
924925
})
925-
.and_then(|(n, s)| s.ready(n))
926926
.boxed()
927927
}
928928

tokio-postgres/src/test.rs

+9
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,15 @@ fn prepare_execute() {
132132
l.run(done).unwrap();
133133
}
134134

135+
#[test]
136+
fn prepare_execute_rows() {
137+
let mut l = Core::new().unwrap();
138+
let done = Connection::connect("postgres://postgres@localhost", TlsMode::None, &l.handle())
139+
.then(|c| c.unwrap().prepare("SELECT 1"))
140+
.and_then(|(s, c)| c.execute(&s, &[]));
141+
l.run(done).unwrap();
142+
}
143+
135144
#[test]
136145
fn query() {
137146
let mut l = Core::new().unwrap();

0 commit comments

Comments
 (0)