feat(import): 添加 SQL 脚本导入功能支持 - #7123
Conversation
- 在贡献指南中添加了 Strawberry Perl 安装步骤 - 在入门指南中更新了 Windows 依赖项说明 - 为 Windows 平台提供了 Perl 安装命令 - 添加了关于 SQLite-SQLCipher 编译需求的说明 - 说明了 OpenSSL 配置脚本需要 Perl 的原因 - 提供了安装后重新打开终端的提示
- 在贡献指南中添加了 Strawberry Perl 安装步骤 - 在入门指南中更新了 Windows 依赖项说明 - 为 Windows 平台提供了 Perl 安装命令 - 添加了关于 SQLite-SQLCipher 编译需求的说明 - 说明了 OpenSSL 配置脚本需要 Perl 的原因 - 提供了安装后重新打开终端的提示
- 在贡献指南中添加了 Strawberry Perl 安装步骤 - 在入门指南中更新了 Windows 依赖项说明 - 为 Windows 平台提供了 Perl 安装命令 - 添加了关于 SQLite-SQLCipher 编译需求的说明 - 说明了 OpenSSL 配置脚本需要 Perl 的原因 - 提供了安装后重新打开终端的提示
- 在贡献指南中添加了 Strawberry Perl 安装步骤 - 在入门指南中更新了 Windows 依赖项说明 - 为 Windows 平台提供了 Perl 安装命令 - 添加了关于 SQLite-SQLCipher 编译需求的说明 - 说明了 OpenSSL 配置脚本需要 Perl 的原因 - 提供了安装后重新打开终端的提示
- 在贡献指南中添加了 Strawberry Perl 安装步骤 - 在入门指南中更新了 Windows 依赖项说明 - 为 Windows 平台提供了 Perl 安装命令 - 添加了关于 SQLite-SQLCipher 编译需求的说明 - 说明了 OpenSSL 配置脚本需要 Perl 的原因 - 提供了安装后重新打开终端的提示
- 在贡献指南中添加了 Strawberry Perl 安装步骤 - 在入门指南中更新了 Windows 依赖项说明 - 为 Windows 平台提供了 Perl 安装命令 - 添加了关于 SQLite-SQLCipher 编译需求的说明 - 说明了 OpenSSL 配置脚本需要 Perl 的原因 - 提供了安装后重新打开终端的提示
- 在导入对话框中添加 SQL 格式选项和文件图标 - 实现 SQL 脚本中 INSERT 语句的数据解析功能 - 支持多种 SQL 标识符格式和字符串转义 - 添加 SQL 文件的文本编码检测和处理 - 扩展文件选择器支持 .sql 文件扩展名 - 更新多语言资源文件中的 SQL 相关翻译 - 添加 SQL 导入功能的单元测试用例 - 重构代码以统一文本源的编码处理逻辑
- 为 merged_path_with_dir 函数添加详细注释说明跨平台测试配置原因 - 调整条件编译属性从 #[cfg(test)] 改为 #[cfg(all(test, not(windows)))] - 统一 SQL 注释处理逻辑,合并 '--' 和 '#' 行注释的判断条件 - 简化 table_import 模块中的注释跳过逻辑实现
- 在贡献指南中添加了 Strawberry Perl 安装步骤 - 在入门指南中更新了 Windows 依赖项说明 - 为 Windows 平台提供了 Perl 安装命令 - 添加了关于 SQLite-SQLCipher 编译需求的说明 - 说明了 OpenSSL 配置脚本需要 Perl 的原因 - 提供了安装后重新打开终端的提示
- 在贡献指南中添加了 Strawberry Perl 安装步骤 - 在入门指南中更新了 Windows 依赖项说明 - 为 Windows 平台提供了 Perl 安装命令 - 添加了关于 SQLite-SQLCipher 编译需求的说明 - 说明了 OpenSSL 配置脚本需要 Perl 的原因 - 提供了安装后重新打开终端的提示
- 在贡献指南中添加了 Strawberry Perl 安装步骤 - 在入门指南中更新了 Windows 依赖项说明 - 为 Windows 平台提供了 Perl 安装命令 - 添加了关于 SQLite-SQLCipher 编译需求的说明 - 说明了 OpenSSL 配置脚本需要 Perl 的原因 - 提供了安装后重新打开终端的提示
- 在贡献指南中添加了 Strawberry Perl 安装步骤 - 在入门指南中更新了 Windows 依赖项说明 - 为 Windows 平台提供了 Perl 安装命令 - 添加了关于 SQLite-SQLCipher 编译需求的说明 - 说明了 OpenSSL 配置脚本需要 Perl 的原因 - 提供了安装后重新打开终端的提示
- 在贡献指南中添加了 Strawberry Perl 安装步骤 - 在入门指南中更新了 Windows 依赖项说明 - 为 Windows 平台提供了 Perl 安装命令 - 添加了关于 SQLite-SQLCipher 编译需求的说明 - 说明了 OpenSSL 配置脚本需要 Perl 的原因 - 提供了安装后重新打开终端的提示
- 在贡献指南中添加了 Strawberry Perl 安装步骤 - 在入门指南中更新了 Windows 依赖项说明 - 为 Windows 平台提供了 Perl 安装命令 - 添加了关于 SQLite-SQLCipher 编译需求的说明 - 说明了 OpenSSL 配置脚本需要 Perl 的原因 - 提供了安装后重新打开终端的提示
t8y2
left a comment
There was a problem hiding this comment.
request changes: the SQL-script import path can silently change valid SQL data and statement semantics.
-
crates/dbx-core/src/table_import.rs:1309applies MySQL-style backslash escaping to ordinary strings, while theE'...'handling around line 1472 does the opposite of PostgreSQL semantics. The same parser converts expressions such asNOW()into the string'NOW()', and accepts MySQLREPLACEbut later regenerates a normalINSERT.PostgreSQL only gives backslashes special meaning in escape string constants: https://www.postgresql.org/docs/current/sql-syntax-lexical.html
MySQLREPLACEhas delete-and-insert conflict semantics, not ordinary INSERT semantics: https://dev.mysql.com/doc/refman/8.0/en/replace.htmlPlease make the source dialect explicit and preserve strings, expressions, special literals, and statement type. Unsupported constructs should be rejected rather than silently converted.
-
register_sql_insert_columns()compares already-unquoted table names witheq_ignore_ascii_case(), so PostgreSQL"Foo"and"foo"are merged into one import target. Preserve quote state and apply the source dialect's identifier rules. -
The implementation reads, decodes, splits, and materializes the complete file before its first cancellation check. A permitted 100 MiB script therefore has no parsing progress or cancellation and creates several full in-memory copies. Please use a bounded streaming statement/row producer with cancellation and byte progress during parsing.
DBX already has a dialect-aware splitter in crates/dbx-core/src/sql.rs; MySQL client DELIMITER semantics are documented here: https://dev.mysql.com/doc/refman/8.0/en/mysql-commands.html
手写的 INSERT/REPLACE 解析器会把 SQL 脚本转换成表格再重写,从而静默改变 合法数据与语句语义:MySQL 反斜杠转义被套用到 PostgreSQL、E'...' 转义方向 相反、NOW() 被转成字符串、REPLACE 被重写为 INSERT、引号标识符大小写丢失, 且不支持 DELIMITER、美元引用等方言切分。 改为复用已有的方言感知 SQL 脚本执行链路:.sql 文件通过执行 SQL 脚本入口 处理,语句语义由目标数据库端保证,不再作为表格导入的数据源。
原有手写 INSERT/REPLACE 解析器会把 SQL 脚本转换成表格再重写,从而静默改变 合法数据与语句语义。改为复用已有设施: - 用 sql.rs 的方言感知拆分器替代按分号裸切(支持 MySQL DELIMITER、PostgreSQL 美元引用、SQL Server GO、Oracle / 等)。 - 用 sqlparser 按源方言解析 INSERT:字符串转义(MySQL 反斜杠 vs PostgreSQL 标准字符串/E'...')与标识符引号状态由解析器正确处理。 - 给 TableImportParseOptions 增加 sqlDialect,前端传入目标连接类型。 - 标识符按方言比较,PostgreSQL 不再把 "Foo" 与 foo 错误合并。 - 无法用普通 INSERT 无损表达的构造明确拒绝:REPLACE、INSERT IGNORE/SELECT/SET、 ON CONFLICT、NOW() 等表达式、X'/B' 二进制字面量、占位符。
The remote revert dropped SQL script import because the original could silently change data and statement semantics. Keep the local rewrite that parses INSERT via a dialect-aware parser (sqlparser) and rejects non-lossless constructs (REPLACE, INSERT IGNORE/SELECT/SET, ON CONFLICT, binary literals, expressions), resolving the review concern instead of removing the feature.
SQL 脚本导入此前只接受字面量,遇到 TO_DATE(...) 这类构造会拒绝。本次放宽为 "无损字面量展开": - 白名单 TO_DATE / TO_TIMESTAMP / TO_TIMESTAMP_TZ:参数全部是字符串字面量时, 按第一个字符串实参导入(等价于把该日期时间值按其规范字符串形式存储); - 支持 DATE '...' / TIMESTAMP '...' / TIME '...' 标准类型字面量; - 非字面量参数(列引用、表达式、命名参数等)、非白名单函数、INTERVAL 等 仍按"表达式不支持"明确拒绝,不静默改写语句语义。
变更说明
变更类型
涉及前端
验证
make check通过make cargo-check-fast通过关联 Issue
Close #6965