Skip to content

Commit fea273f

Browse files
committed
mssql tinyint revert
1 parent a1f2e61 commit fea273f

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,27 @@ use crate::types::Type;
77

88
impl Type<Mssql> for u8 {
99
fn type_info() -> MssqlTypeInfo {
10-
<i8 as Type<Mssql>>::type_info()
10+
MssqlTypeInfo(TypeInfo::new(DataType::IntN, 1))
1111
}
1212

1313
fn compatible(ty: &MssqlTypeInfo) -> bool {
14-
<i8 as Type<Mssql>>::compatible(ty)
14+
matches!(ty.0.ty, DataType::TinyInt | DataType::IntN) && ty.0.size == 1
1515
}
1616
}
1717

1818
impl Encode<'_, Mssql> for u8 {
1919
fn encode_by_ref(&self, buf: &mut Vec<u8>) -> IsNull {
20-
let v = i8::try_from(*self).unwrap_or_else(|_e| {
21-
log::warn!("cannot encode {self} as a signed mssql tinyint");
22-
i8::MAX
23-
});
24-
<i8 as Encode<'_, Mssql>>::encode_by_ref(&v, buf)
20+
buf.extend(&[*self]);
21+
IsNull::No
2522
}
2623
}
2724

2825
impl Decode<'_, Mssql> for u8 {
2926
fn decode(value: MssqlValueRef<'_>) -> Result<Self, BoxDynError> {
30-
let v = <i8 as Decode<'_, Mssql>>::decode(value)?;
31-
Ok(u8::try_from(v)?)
27+
Ok(*value
28+
.as_bytes()?
29+
.get(0)
30+
.ok_or("Invalid numeric value length")?)
3231
}
3332
}
3433

0 commit comments

Comments
 (0)