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

Commit91b2187

Browse files
authored
Merge pull request#937 from NAlexPear/encode_format_types
Encode Format based on Type
2 parents8f955eb +8158eed commit91b2187

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

‎postgres-types/src/lib.rs‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ pub trait ToSql: fmt::Debug {
836836
) ->Result<IsNull,Box<dynError +Sync +Send>>;
837837

838838
/// Specify the encode format
839-
fnencode_format(&self) ->Format{
839+
fnencode_format(&self,_ty:&Type) ->Format{
840840
Format::Binary
841841
}
842842
}
@@ -868,8 +868,8 @@ where
868868
T::accepts(ty)
869869
}
870870

871-
fnencode_format(&self) ->Format{
872-
(*self).encode_format()
871+
fnencode_format(&self,ty:&Type) ->Format{
872+
(*self).encode_format(ty)
873873
}
874874

875875
to_sql_checked!();
@@ -891,9 +891,9 @@ impl<T: ToSql> ToSql for Option<T> {
891891
<TasToSql>::accepts(ty)
892892
}
893893

894-
fnencode_format(&self) ->Format{
894+
fnencode_format(&self,ty:&Type) ->Format{
895895
matchself{
896-
Some(ref val) => val.encode_format(),
896+
Some(ref val) => val.encode_format(ty),
897897
None =>Format::Binary,
898898
}
899899
}

‎tokio-postgres/src/query.rs‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,25 +156,29 @@ where
156156
I:IntoIterator<Item =P>,
157157
I::IntoIter:ExactSizeIterator,
158158
{
159-
let(param_formats, params):(Vec<_>,Vec<_>) = params
160-
.into_iter()
161-
.map(|p|(p.borrow_to_sql().encode_format()asi16, p))
162-
.unzip();
159+
let param_types = statement.params();
163160
let params = params.into_iter();
164161

165162
assert!(
166-
statement.params().len() == params.len(),
163+
param_types.len() == params.len(),
167164
"expected {} parameters but got {}",
168-
statement.params().len(),
165+
param_types.len(),
169166
params.len()
170167
);
171168

169+
let(param_formats, params):(Vec<_>,Vec<_>) = params
170+
.zip(param_types.iter())
171+
.map(|(p, ty)|(p.borrow_to_sql().encode_format(ty)asi16, p))
172+
.unzip();
173+
174+
let params = params.into_iter();
175+
172176
letmut error_idx =0;
173177
let r = frontend::bind(
174178
portal,
175179
statement.name(),
176180
param_formats,
177-
params.zip(statement.params()).enumerate(),
181+
params.zip(param_types).enumerate(),
178182
|(idx,(param, ty)), buf|match param.borrow_to_sql().to_sql_checked(ty, buf){
179183
Ok(IsNull::No) =>Ok(postgres_protocol::IsNull::No),
180184
Ok(IsNull::Yes) =>Ok(postgres_protocol::IsNull::Yes),

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp