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(transfer): keep backslashes literal for Oracle-family and SQLite targets

ordinary being787899f2010f
diff --git a/crates/dbx-core/src/data/transfer.rs b/crates/dbx-core/src/data/transfer.rs
index 29d981b107..1a3bcdef49 100644
--- a/crates/dbx-core/src/data/transfer.rs
+++ b/crates/dbx-core/src/data/transfer.rs
@@ -2238,6 +2238,24 @@ fn is_postgres_family_target(target_db: &DatabaseType) -> bool {
)
}
+/// Engines whose ordinary string literals keep a backslash literal, so a
+/// transferred value must not have its backslashes doubled: `C:\tmp` has to stay
+/// `'C:\tmp'` instead of becoming `'C:\\tmp'`. Mirrors the SQL export path
+/// (`quote_export_sql_string_for_database`) and the grid's copy-as-SQL path,
+/// which both only double backslashes for dialects whose escape table has one.
+fn keeps_backslash_literal(target_db: &DatabaseType) -> bool {
+ matches!(
+ target_db,
+ DatabaseType::Oracle
+ | DatabaseType::OceanbaseOracle
+ | DatabaseType::Dameng
+ | DatabaseType::Sqlite
+ | DatabaseType::Rqlite
+ | DatabaseType::Turso
+ | DatabaseType::CloudflareD1
+ )
+}
+
fn is_mysql_numeric_base_type(data_type: &str) -> bool {
let normalized = data_type.trim().to_ascii_lowercase();
let base = normalized.split(['(', ' ']).next().unwrap_or("");
@@ -3083,6 +3101,7 @@ pub fn escape_value_typed(val: &serde_json::Value, db_type: &DatabaseType, colum
}
let escaped = if is_postgres_family_target(db_type)
|| matches!(db_type, DatabaseType::SqlServer | DatabaseType::H2)
+ || keeps_backslash_literal(db_type)
{
literal.replace('\'', "''")
} else {
@@ -12347,6 +12366,31 @@ CREATE TABLE "Other"."prefix""Source"."NAME" ("ID" INT);"#;
}
}
+ #[test]
+ fn transfer_keeps_backslashes_literal_for_oracle_family_and_sqlite() {
+ for db_type in [
+ DatabaseType::Oracle,
+ DatabaseType::OceanbaseOracle,
+ DatabaseType::Dameng,
+ DatabaseType::Sqlite,
+ DatabaseType::Rqlite,
+ DatabaseType::Turso,
+ DatabaseType::CloudflareD1,
+ ] {
+ assert_eq!(
+ escape_value_typed(&json!(r"C:\tmp\o'clock"), &db_type, Some("VARCHAR(64)")),
+ r"'C:\tmp\o''clock'",
+ "{db_type:?}"
+ );
+ }
+
+ // Dialects whose escape table does have a backslash escape keep doubling it.
+ assert_eq!(
+ escape_value_typed(&json!(r"C:\tmp\o'clock"), &DatabaseType::Mysql, Some("varchar(64)")),
+ r"'C:\\tmp\\o''clock'"
+ );
+ }
+
#[test]
fn h2_transfer_literals_preserve_json_binary_and_backslashes() {
assert_eq!(