Skip to content

Commit 2598f9e

Browse files
Fix encoding large u32 & u16
Doing try_from will fail here too with TryFromIntError. Tracking in #14
1 parent c875284 commit 2598f9e

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

sqlx-core/src/mssql/types/uint.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,7 @@ impl Type<Mssql> for u16 {
4343

4444
impl Encode<'_, Mssql> for u16 {
4545
fn encode_by_ref(&self, buf: &mut Vec<u8>) -> IsNull {
46-
let v = i16::try_from(*self).unwrap_or_else(|_e| {
47-
log::warn!("cannot encode {self} as a signed mssql smallint");
48-
i16::MAX
49-
});
46+
let v = *self as i16;
5047
<i16 as Encode<'_, Mssql>>::encode_by_ref(&v, buf)
5148
}
5249
}
@@ -70,10 +67,7 @@ impl Type<Mssql> for u32 {
7067

7168
impl Encode<'_, Mssql> for u32 {
7269
fn encode_by_ref(&self, buf: &mut Vec<u8>) -> IsNull {
73-
let v = i32::try_from(*self).unwrap_or_else(|_e| {
74-
log::warn!("cannot encode {self} as a signed mssql int");
75-
i32::MAX
76-
});
70+
let v = *self as i32;
7771
<i32 as Encode<'_, Mssql>>::encode_by_ref(&v, buf)
7872
}
7973
}
@@ -97,10 +91,7 @@ impl Type<Mssql> for u64 {
9791

9892
impl Encode<'_, Mssql> for u64 {
9993
fn encode_by_ref(&self, buf: &mut Vec<u8>) -> IsNull {
100-
let v = i64::try_from(*self).unwrap_or_else(|_e| {
101-
log::warn!("cannot encode {self} as a signed mssql bigint");
102-
i64::MAX
103-
});
94+
let v = *self as i64;
10495
<i64 as Encode<'_, Mssql>>::encode_by_ref(&v, buf)
10596
}
10697
}

0 commit comments

Comments
 (0)