fix(cache): 修复 tableExists 方法以正确检测达梦数据库中的表存在性
- 修改 tableExists 方法,使用 COUNT(*) 查询当前 schema 下的表,避免因用户权限导致的误判 - 更新 ObjToFloat64、ObjToInt64 和 ObjToStr 方法,增加对多种整数和布尔类型的支持 - 在 Row 方法中处理 time.Time 类型,确保与 MySQL 兼容的字符串格式输出
This commit is contained in:
Vendored
+7
-3
@@ -136,9 +136,13 @@ func (that *CacheDb) tableExists(tableName string) bool {
|
||||
return len(res) != 0
|
||||
|
||||
case "dm", "dameng":
|
||||
// 双引号创建的表名保留原始大小写,不能 ToUpper
|
||||
res := that.Db.Query(`SELECT TABLE_NAME FROM USER_TABLES WHERE TABLE_NAME='` + tableName + `'`)
|
||||
return len(res) != 0
|
||||
// USER_TABLES 仅含当前登录用户(如 SYSDBA)拥有的表。
|
||||
// 当连接 schema(如 ZWBG)与登录用户不同时,ZWBG 的表不会出现在
|
||||
// USER_TABLES 中,导致 tableExists 误判为"不存在",进而触发重复建表失败。
|
||||
// 改为直接 SELECT COUNT(*) 探测当前 schema 下的可访问性:
|
||||
// 表存在则返回 1 行,表不存在则报错返回空结果(nil)。
|
||||
res := that.Db.Query(`SELECT COUNT(*) as cnt FROM "` + tableName + `"`)
|
||||
return len(res) > 0
|
||||
}
|
||||
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user