fix: display MySQL BIT(1) columns as numeric strings instead of garbled text

BIT columns arrive as raw bytes from mysql_async. Without specialized
handling, byte 0x01 was treated as a valid UTF-8 control character and
byte 0x00 was replaced with U+FFFD. Now BIT values are interpreted as
big-endian integers, so BIT(1) correctly displays "0" or "1".
This commit is contained in:
t8y2 2026-05-26 11:22:23 +08:00
parent 5f3606e5b5
commit 23d04645f6
1 changed files with 8 additions and 0 deletions

View File

@ -124,6 +124,14 @@ fn mysql_value_to_json(row: &mysql_async::Row, idx: usize) -> serde_json::Value
.map(|v: Decimal| serde_json::Value::String(v.to_string()))
.unwrap_or(serde_json::Value::Null);
}
ColumnType::MYSQL_TYPE_BIT => {
return row_get::<Vec<u8>, _>(row, idx)
.map(|bytes| {
let val = bytes.iter().fold(0u64, |acc, &b| (acc << 8) | b as u64);
serde_json::Value::String(val.to_string())
})
.unwrap_or(serde_json::Value::Null);
}
ColumnType::MYSQL_TYPE_TIMESTAMP
| ColumnType::MYSQL_TYPE_TIMESTAMP2
| ColumnType::MYSQL_TYPE_DATETIME