Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

Commit 24ed86a

Browse files
authored
fix: handle description a bit higher in the execution (#10)
1 parent 5e75a39 commit 24ed86a

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed

tokio-postgres/src/query.rs

+25-21
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,11 @@ where
5353
} else {
5454
encode(client, &statement, params)?
5555
};
56-
let (statement, responses) = start(client, buf).await?;
56+
57+
let responses = start(client, buf).await?;
58+
5759
Ok(RowStream {
58-
statement,
60+
statement: None,
5961
responses,
6062
rows_affected: None,
6163
command_tag: None,
@@ -116,11 +118,11 @@ where
116118
})?;
117119

118120
// now read the responses
119-
let (statement, responses) = start(client, buf).await?;
121+
let responses = start(client, buf).await?;
120122

121123
Ok(RowStream {
122124
parameter_description: None,
123-
statement,
125+
statement: None,
124126
responses,
125127
command_tag: None,
126128
status: None,
@@ -189,7 +191,8 @@ where
189191
} else {
190192
encode(client, &statement, params)?
191193
};
192-
let (_statement, mut responses) = start(client, buf).await?;
194+
195+
let mut responses = start(client, buf).await?;
193196

194197
let mut rows = 0;
195198
loop {
@@ -205,27 +208,13 @@ where
205208
}
206209
}
207210

208-
async fn start(client: &InnerClient, buf: Bytes) -> Result<(Option<Statement>, Responses), Error> {
209-
let mut parameter_description: Option<ParameterDescriptionBody> = None;
210-
let mut statement = None;
211+
async fn start(client: &InnerClient, buf: Bytes) -> Result<Responses, Error> {
211212
let mut responses = client.send(RequestMessages::Single(FrontendMessage::Raw(buf)))?;
212213

213214
loop {
214215
match responses.next().await? {
215216
Message::ParseComplete => {}
216-
Message::BindComplete => return Ok((statement, responses)),
217-
Message::ParameterDescription(body) => {
218-
parameter_description = Some(body); // tooo-o-ooo-o loooove
219-
}
220-
Message::NoData => {
221-
statement = Some(make_statement(parameter_description.take().unwrap(), None)?);
222-
}
223-
Message::RowDescription(body) => {
224-
statement = Some(make_statement(
225-
parameter_description.take().unwrap(),
226-
Some(body),
227-
)?);
228-
}
217+
Message::BindComplete => return Ok(responses),
229218
m => return Err(Error::unexpected_message(m)),
230219
}
231220
}
@@ -360,6 +349,21 @@ impl Stream for RowStream {
360349
*this.command_tag = Some(tag.to_string());
361350
}
362351
}
352+
Message::ParameterDescription(body) => {
353+
*this.parameter_description = Some(body);
354+
}
355+
Message::NoData => {
356+
*this.statement = Some(make_statement(
357+
this.parameter_description.take().unwrap(),
358+
None,
359+
)?);
360+
}
361+
Message::RowDescription(body) => {
362+
*this.statement = Some(make_statement(
363+
this.parameter_description.take().unwrap(),
364+
Some(body),
365+
)?);
366+
}
363367
Message::EmptyQueryResponse | Message::PortalSuspended => {}
364368
Message::ReadyForQuery(status) => {
365369
*this.status = Some(status.status());

0 commit comments

Comments
 (0)