-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: mssql uses unsigned for tinyint instead of signed (#2074)
- Loading branch information
Showing
3 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters