From 2fb0c545b7a24ce5e1d1dcce536826c608e563c7 Mon Sep 17 00:00:00 2001 From: Zachery Gyurkovitz Date: Fri, 19 Jul 2019 14:13:23 -0700 Subject: [PATCH] Implement `get_results` --- sqlx-postgres/src/connection/prepare.rs | 44 ++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/sqlx-postgres/src/connection/prepare.rs b/sqlx-postgres/src/connection/prepare.rs index 92d3289a0..2f7fec873 100644 --- a/sqlx-postgres/src/connection/prepare.rs +++ b/sqlx-postgres/src/connection/prepare.rs @@ -126,4 +126,46 @@ impl<'a> Prepare<'a> { // FIXME: This is an end-of-file error. How we should bubble this up here? unreachable!() } -} \ No newline at end of file + + #[inline] + pub async fn get_results(self) -> io::Result> { + proto::bind::trailer( + &mut self.connection.wbuf, + self.bind_state, + self.bind_values, + &[], + ); + + self.connection.send(Execute::new("", 0)); + self.connection.send(Sync); + self.connection.flush().await?; + + let mut rows = vec![]; + + while let Some(message) = self.connection.receive().await? { + match message { + Message::BindComplete | Message::ParseComplete => { + // Indicates successful completion of a phase + } + + Message::DataRow(row) => { + rows.push(row); + } + + Message::CommandComplete(_) => {} + + Message::ReadyForQuery(_) => { + // Successful completion of the whole cycle + return Ok(rows); + } + + message => { + unimplemented!("received {:?} unimplemented message", message); + } + } + } + + // FIXME: This is an end-of-file error. How we should bubble this up here? + unreachable!() + } +}