mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-06-05 14:09:36 +08:00
🐛 fix(kingbase): 统一金仓标识符引用策略
- 标识符处理:下沉 Kingbase 引用逻辑,普通小写 schema/table 不再强制双引号包裹 - 表操作修复:修复截断、清空、导入、导出等路径生成异常双引号 SQL - 同步链路修复:统一数据同步、预览、迁移建表中的 Kingbase schema.table 拼接规则 - 自定义驱动兼容:补齐 kingbase8/kingbasees/kingbasev8 别名归一与写入路径处理 - 回归覆盖:新增 ldf_server.andon_events、转义引号、保留字和大小写标识符测试
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
package sync
|
||||
|
||||
import "strings"
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"GoNavi-Wails/internal/db"
|
||||
)
|
||||
|
||||
func normalizeSyncMode(mode string) string {
|
||||
m := strings.ToLower(strings.TrimSpace(mode))
|
||||
@@ -21,9 +25,11 @@ func quoteIdentByType(dbType string, ident string) string {
|
||||
return ident
|
||||
}
|
||||
|
||||
switch dbType {
|
||||
switch normalizeMigrationDBType(dbType) {
|
||||
case "mysql", "mariadb", "oceanbase", "diros", "sphinx", "clickhouse", "tdengine":
|
||||
return "`" + strings.ReplaceAll(ident, "`", "``") + "`"
|
||||
case "kingbase":
|
||||
return db.QuoteKingbaseIdentifier(ident)
|
||||
case "sqlserver":
|
||||
escaped := strings.ReplaceAll(ident, "]", "]]")
|
||||
return "[" + escaped + "]"
|
||||
@@ -38,9 +44,21 @@ func quoteQualifiedIdentByType(dbType string, ident string) string {
|
||||
return raw
|
||||
}
|
||||
|
||||
normalizedType := normalizeMigrationDBType(dbType)
|
||||
if normalizedType == "kingbase" {
|
||||
schema, table := db.SplitKingbaseQualifiedName(raw)
|
||||
if table == "" {
|
||||
return quoteIdentByType(normalizedType, raw)
|
||||
}
|
||||
if schema == "" {
|
||||
return quoteIdentByType(normalizedType, table)
|
||||
}
|
||||
return quoteIdentByType(normalizedType, schema) + "." + quoteIdentByType(normalizedType, table)
|
||||
}
|
||||
|
||||
parts := strings.Split(raw, ".")
|
||||
if len(parts) <= 1 {
|
||||
return quoteIdentByType(dbType, raw)
|
||||
return quoteIdentByType(normalizedType, raw)
|
||||
}
|
||||
|
||||
quotedParts := make([]string, 0, len(parts))
|
||||
@@ -49,11 +67,11 @@ func quoteQualifiedIdentByType(dbType string, ident string) string {
|
||||
if part == "" {
|
||||
continue
|
||||
}
|
||||
quotedParts = append(quotedParts, quoteIdentByType(dbType, part))
|
||||
quotedParts = append(quotedParts, quoteIdentByType(normalizedType, part))
|
||||
}
|
||||
|
||||
if len(quotedParts) == 0 {
|
||||
return quoteIdentByType(dbType, raw)
|
||||
return quoteIdentByType(normalizedType, raw)
|
||||
}
|
||||
return strings.Join(quotedParts, ".")
|
||||
}
|
||||
@@ -65,6 +83,17 @@ func normalizeSchemaAndTable(dbType string, dbName string, tableName string) (st
|
||||
return rawDB, rawTable
|
||||
}
|
||||
|
||||
normalizedType := normalizeMigrationDBType(dbType)
|
||||
if normalizedType == "kingbase" {
|
||||
schema, table := db.SplitKingbaseQualifiedName(rawTable)
|
||||
if schema != "" && table != "" {
|
||||
return schema, table
|
||||
}
|
||||
if table != "" {
|
||||
return "public", table
|
||||
}
|
||||
}
|
||||
|
||||
if parts := strings.SplitN(rawTable, ".", 2); len(parts) == 2 {
|
||||
schema := strings.TrimSpace(parts[0])
|
||||
table := strings.TrimSpace(parts[1])
|
||||
@@ -73,7 +102,7 @@ func normalizeSchemaAndTable(dbType string, dbName string, tableName string) (st
|
||||
}
|
||||
}
|
||||
|
||||
switch strings.ToLower(strings.TrimSpace(dbType)) {
|
||||
switch normalizedType {
|
||||
case "postgres", "kingbase", "highgo", "vastbase", "opengauss":
|
||||
return "public", rawTable
|
||||
case "duckdb":
|
||||
@@ -92,7 +121,7 @@ func qualifiedNameForQuery(dbType string, schema string, table string, original
|
||||
return raw
|
||||
}
|
||||
|
||||
switch strings.ToLower(strings.TrimSpace(dbType)) {
|
||||
switch normalizeMigrationDBType(dbType) {
|
||||
case "postgres", "kingbase", "highgo", "vastbase", "opengauss":
|
||||
s := strings.TrimSpace(schema)
|
||||
if s == "" {
|
||||
|
||||
Reference in New Issue
Block a user