Skip to content

Commit d04a5e8

Browse files
authored
Merge pull request #92 from 0xdeafbeef/main
fix mysql `TinyInt` serialization
2 parents 1f68c04 + a5a85cb commit d04a5e8

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/mysql/serialize.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub(super) struct ToSqlHelper {
1212
fn to_value((metadata, bind): (MysqlType, Option<Vec<u8>>)) -> Value {
1313
match bind {
1414
Some(bind) => match metadata {
15-
MysqlType::Tiny => Value::Int(bind[0] as _),
15+
MysqlType::Tiny => Value::Int((bind[0] as i8) as i64),
1616
MysqlType::Short => Value::Int(i16::from_ne_bytes(bind.try_into().unwrap()) as _),
1717
MysqlType::Long => Value::Int(i32::from_ne_bytes(bind.try_into().unwrap()) as _),
1818
MysqlType::LongLong => Value::Int(i64::from_ne_bytes(bind.try_into().unwrap())),

tests/type_check.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ async fn check_tiny_int() {
6767
type_check::<_, sql_types::TinyInt>(conn, -1_i8).await;
6868
type_check::<_, sql_types::TinyInt>(conn, i8::MIN).await;
6969
type_check::<_, sql_types::TinyInt>(conn, i8::MAX).await;
70+
71+
// test case for https://github.com/weiznich/diesel_async/issues/91
72+
let res = diesel::dsl::sql::<diesel::sql_types::Bool>("SELECT -1 = ")
73+
.bind::<sql_types::TinyInt, _>(-1)
74+
.get_result::<bool>(conn)
75+
.await
76+
.unwrap();
77+
assert!(res);
7078
}
7179

7280
#[cfg(feature = "mysql")]

0 commit comments

Comments
 (0)