🐛 fix(sync): 修复分页比对与 DDL 字面量缺反斜杠转义导致的错删行与语法错误 DDL

- quoteSyncSQLString 改为方言感知:新增 syncDialectEscapesBackslash,对 mysql/mariadb/
  clickhouse/tdengine/starrocks/diros/oceanbase 先翻倍反斜杠再翻倍单引号;postgres 系、
  sqlserver、sqlite、duckdb 保持原样(翻倍反而会写入两个反斜杠并损坏比对)
- 含反斜杠的主键原先在 IN 列表里被目标库解释成别的字符串,导致源端存在的行先被判为插入、
  反查时又匹配不到而被判为删除并真的从目标删掉,最终 Success=true 但目标永久缺行
- dbType 逐层传入 formatSyncSQLLiteral 的 3 个调用点:buildPKInSelectQuery、
  buildKeysetPagedTableQuery、buildSourceQueryPKInSelectSQL
- escapeMySQLStringLiteral 同类修复:列注释与 DEFAULT 值内联进 MySQL/ClickHouse DDL 时,
  以反斜杠结尾的注释会让 COMMENT '...\' 吞掉闭合引号并生成语法错误的 DDL
- 补 5 项回归测试,方言分组做双向断言(漏加与误加都会失败)
This commit is contained in:
Syngnat
2026-07-26 20:19:29 +08:00
parent 01c3c2f9c9
commit 2bdbdc9382
4 changed files with 142 additions and 10 deletions

View File

@@ -272,7 +272,7 @@ func buildSourceQueryPKInSelectSQL(dbType, sourceQuery string, cols []connection
}
literals := make([]string, 0, len(pkValues))
for _, value := range pkValues {
literal, ok := formatSyncSQLLiteral(value)
literal, ok := formatSyncSQLLiteral(dbType, value)
if ok {
literals = append(literals, literal)
}