fix: mssql uses unsigned for tinyint instead of signed (#2074)

This commit is contained in:
Tobias Tschinkowitz
2022-09-01 03:10:29 +02:00
committed by GitHub
parent 20af5cd9c3
commit 9de70d2e7a
3 changed files with 38 additions and 0 deletions

View File

@@ -6,6 +6,7 @@ mod bool;
mod float;
mod int;
mod str;
mod uint;
impl<'q, T: 'q + Encode<'q, Mssql>> Encode<'q, Mssql> for Option<T> {
fn encode(self, buf: &mut Vec<u8>) -> IsNull {

View File

@@ -0,0 +1,30 @@
use crate::decode::Decode;
use crate::encode::{Encode, IsNull};
use crate::error::BoxDynError;
use crate::mssql::protocol::type_info::{DataType, TypeInfo};
use crate::mssql::{Mssql, MssqlTypeInfo, MssqlValueRef};
use crate::types::Type;
impl Type<Mssql> for u8 {
fn type_info() -> MssqlTypeInfo {
MssqlTypeInfo(TypeInfo::new(DataType::IntN, 1))
}
fn compatible(ty: &MssqlTypeInfo) -> bool {
matches!(ty.0.ty, DataType::TinyInt | DataType::IntN) && ty.0.size == 1
}
}
impl Encode<'_, Mssql> for u8 {
fn encode_by_ref(&self, buf: &mut Vec<u8>) -> IsNull {
buf.extend(&self.to_le_bytes());
IsNull::No
}
}
impl Decode<'_, Mssql> for u8 {
fn decode(value: MssqlValueRef<'_>) -> Result<Self, BoxDynError> {
Ok(value.as_bytes()?[0] as u8)
}
}