Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita344b09

Browse files
committed
fix comment
1 parentc9da397 commita344b09

File tree

3 files changed

+65
-1
lines changed

3 files changed

+65
-1
lines changed

‎tokio-postgres/src/client.rs‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,29 @@ impl Client {
517517
self.execute_raw(statement,slice_iter(params)).await
518518
}
519519

520+
/// Executes a statement, returning the number of rows modified.
521+
///
522+
/// A statement may contain parameters, specified by `$n`, where `n` is the index of the parameter of the list
523+
/// provided, 1-indexed.
524+
///
525+
/// The `statement` argument can either be a `Statement`, or a raw query string. If the same statement will be
526+
/// repeatedly executed (perhaps with different query parameters), consider preparing the statement up front
527+
/// with the `prepare` method.
528+
///
529+
/// If the statement does not modify any rows (e.g. `SELECT`), 0 is returned.
530+
pubasyncfnexecute_typed(
531+
&self,
532+
statement:&str,
533+
params:&[(&(dynToSql +Sync),Type)],
534+
) ->Result<u64,Error>{
535+
query::execute_typed(
536+
&self.inner,
537+
statement,
538+
params.iter().map(|(v, t)|(*v, t.clone())),
539+
)
540+
.await
541+
}
542+
520543
/// The maximally flexible version of [`execute`].
521544
///
522545
/// A statement may contain parameters, specified by `$n`, where `n` is the index of the parameter of the list

‎tokio-postgres/src/query.rs‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,47 @@ where
119119
}
120120
}
121121

122+
pubasyncfnexecute_typed<P,I>(
123+
client:&Arc<InnerClient>,
124+
query:&str,
125+
params:I,
126+
) ->Result<u64,Error>
127+
where
128+
P:BorrowToSql,
129+
I:IntoIterator<Item =(P,Type)>,
130+
{
131+
let buf ={
132+
let params = params.into_iter().collect::<Vec<_>>();
133+
let param_oids = params.iter().map(|(_, t)| t.oid()).collect::<Vec<_>>();
134+
135+
client.with_buf(|buf|{
136+
frontend::parse("", query, param_oids.into_iter(), buf).map_err(Error::parse)?;
137+
encode_bind_raw("", params,"", buf)?;
138+
frontend::describe(b'S',"", buf).map_err(Error::encode)?;
139+
frontend::execute("",0, buf).map_err(Error::encode)?;
140+
frontend::sync(buf);
141+
142+
Ok(buf.split().freeze())
143+
})?
144+
};
145+
146+
letmut responses = client.send(RequestMessages::Single(FrontendMessage::Raw(buf)))?;
147+
148+
letmut rows =0;
149+
150+
loop{
151+
match responses.next().await?{
152+
Message::DataRow(_) =>{}
153+
Message::CommandComplete(body) =>{
154+
rows =extract_row_affected(&body)?;
155+
}
156+
Message::EmptyQueryResponse => rows =0,
157+
Message::ReadyForQuery(_) =>returnOk(rows),
158+
_ =>returnErr(Error::unexpected_message()),
159+
}
160+
}
161+
}
162+
122163
pubasyncfnquery_portal(
123164
client:&InnerClient,
124165
portal:&Portal,

‎tokio-postgres/tests/test/main.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,7 @@ async fn query_typed_one() {
936936
.err()
937937
.unwrap();
938938

939-
// should return error if the number of rows returned is not exactly oneor zero
939+
// should return error if the number of rows returned is not exactly one
940940
client
941941
.query_typed_one("SELECT * FROM foo",&[])
942942
.await

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp