Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

fix(core): guard BIT literal formatting behind MySQL-compatible db_type

t8y28f92eeb638b8
diff --git a/crates/dbx-core/src/database_export.rs b/crates/dbx-core/src/database_export.rs
index 509a16f819..f78a434c02 100644
--- a/crates/dbx-core/src/database_export.rs
+++ b/crates/dbx-core/src/database_export.rs
@@ -839,7 +839,7 @@ mod tests {
assert_eq!(
statements,
- vec!["INSERT INTO `flags` (`enabled`, `mask`, `label`) VALUES (b'1', b'1010', '1010'), (0, 3, 'off');"]
+ vec!["INSERT INTO `flags` (`enabled`, `mask`, `label`) VALUES (b'1', b'1010', '1010'), (b'0', 3, 'off');"]
);
}
diff --git a/crates/dbx-core/src/transfer.rs b/crates/dbx-core/src/transfer.rs
index 30ed7f6747..da0af58d41 100644
--- a/crates/dbx-core/src/transfer.rs
+++ b/crates/dbx-core/src/transfer.rs
@@ -478,24 +478,25 @@ pub fn escape_value_typed(val: &serde_json::Value, db_type: &DatabaseType, colum
}
}
},
- serde_json::Value::Number(n) => {
- if column_type.is_some_and(is_mysql_bit_type) {
- format!("b'{}'", n.to_string())
- } else {
- n.to_string()
+ serde_json::Value::Number(n) => match db_type {
+ DatabaseType::Mysql | DatabaseType::Doris | DatabaseType::StarRocks => {
+ if column_type.is_some_and(is_mysql_bit_type) {
+ format!("b'{}'", n.to_string())
+ } else {
+ n.to_string()
+ }
}
- }
+ _ => n.to_string(),
+ },
serde_json::Value::String(s) => {
- if column_type.is_some_and(is_mysql_bit_type) {
- format!(
- "b'{}'",
- format_literal_string(s, db_type, column_type).replace('\\', "\\\\").replace('\'', "''")
- )
- } else {
- format!(
- "'{}'",
- format_literal_string(s, db_type, column_type).replace('\\', "\\\\").replace('\'', "''")
- )
+ let escaped = format_literal_string(s, db_type, column_type).replace('\\', "\\\\").replace('\'', "''");
+ match db_type {
+ DatabaseType::Mysql | DatabaseType::Doris | DatabaseType::StarRocks
+ if column_type.is_some_and(is_mysql_bit_type) =>
+ {
+ format!("b'{escaped}'")
+ }
+ _ => format!("'{escaped}'"),
}
}
serde_json::Value::Array(arr) => match db_type {