Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/change-plugin-sql-add-more-mysql-data-types.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"sql": minor
"sql-js": minor
---

Add support for MySQL `DECIMAL`, `SET`, `GEOMETRY`, `BINARY`, `VARBINARY` data types. Also fixes the `TINIYBLOB` => `TINYBLOB` spelling.
36 changes: 35 additions & 1 deletion plugins/sql/src/decode/mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,42 @@ pub(crate) fn to_json(v: MySqlValueRef) -> Result<JsonValue, Error> {
JsonValue::Null
}
}
"DECIMAL" => {
if let Ok(v) = ValueRef::to_owned(&v).try_decode::<rust_decimal::Decimal>() {
JsonValue::String(v.to_string())
} else {
JsonValue::Null
}
}
"SET" | "GEOMETRY" | "BIT" => {
if let Ok(v) = ValueRef::to_owned(&v).try_decode::<String>() {
JsonValue::String(v)
} else {
JsonValue::Null
}
}
"JSON" => ValueRef::to_owned(&v).try_decode().unwrap_or_default(),
"TINIYBLOB" | "MEDIUMBLOB" | "BLOB" | "LONGBLOB" => {
"BINARY" | "VARBINARY" => {
// MySQL information_schema often returns text data as VARBINARY,
// so try decoding as UTF-8 string first, then fall back to byte array
if let Ok(v) = ValueRef::to_owned(&v).try_decode::<Vec<u8>>() {
match String::from_utf8(v) {
Ok(s) => JsonValue::String(s),
Err(e) => {
let bytes = e.into_bytes();
JsonValue::Array(
bytes
.into_iter()
.map(|n| JsonValue::Number(n.into()))
.collect(),
)
}
}
} else {
JsonValue::Null
}
}
"TINYBLOB" | "MEDIUMBLOB" | "BLOB" | "LONGBLOB" => {
if let Ok(v) = ValueRef::to_owned(&v).try_decode::<Vec<u8>>() {
JsonValue::Array(v.into_iter().map(|n| JsonValue::Number(n.into())).collect())
} else {
Expand Down
Loading