82 lines
2.6 KiB
Markdown
82 lines
2.6 KiB
Markdown
|
|
---
|
|||
|
|
name: 修复DM类型映射大小写
|
|||
|
|
overview: DM 返回的列类型为大写(BIGINT、VARCHAR、INT、TIMESTAMP),但 ColumnDataType 的匹配键是小写且 strings.Contains 区分大小写,导致类型映射全部失败。
|
|||
|
|
todos:
|
|||
|
|
- id: fix-type-case
|
|||
|
|
content: 修改 makecode.go 类型比较加 strings.ToLower 忽略大小写
|
|||
|
|
status: completed
|
|||
|
|
- id: add-dm-types
|
|||
|
|
content: 在 config.go 的 ColumnDataType 中追加 DM 特有数据类型映射
|
|||
|
|
status: completed
|
|||
|
|
isProject: false
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
# 修复达梦数据库列类型映射失败
|
|||
|
|
|
|||
|
|
## 问题分析
|
|||
|
|
|
|||
|
|
通过 MCP 查询 `adminDB.json` 确认:大量字段 type 仍为 DM 原始类型(`BIGINT`、`VARCHAR`、`INT`、`TIMESTAMP`、`DECIMAL`),未映射到框架类型(`number`、`text`、`time`),导致前端编辑页无法识别控件类型。
|
|||
|
|
|
|||
|
|
### 根因
|
|||
|
|
|
|||
|
|
[config.go](d:\work\hotimev1.5\code\config.go) 第 43-59 行定义的 `ColumnDataType` 映射表键全部为小写:
|
|||
|
|
|
|||
|
|
```go
|
|||
|
|
var ColumnDataType = map[string]string{
|
|||
|
|
"int": "number",
|
|||
|
|
"char": "text",
|
|||
|
|
"text": "text",
|
|||
|
|
"time": "time",
|
|||
|
|
// ...
|
|||
|
|
}
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
[makecode.go](d:\work\hotimev1.5\code\makecode.go) 第 191-194 行的匹配逻辑使用 `strings.Contains`,**区分大小写**:
|
|||
|
|
|
|||
|
|
```go
|
|||
|
|
for k, v1 := range ColumnDataType {
|
|||
|
|
if strings.Contains(info.GetString("type"), k) { // "BIGINT" 不包含 "int"
|
|||
|
|
info["type"] = v1
|
|||
|
|
break
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
DM 返回的类型全部为大写(`INT`、`VARCHAR`、`BIGINT`),而键为小写(`int`、`char`),`strings.Contains("BIGINT", "int")` 返回 `false`,映射全部跳过。
|
|||
|
|
|
|||
|
|
## 修复方案
|
|||
|
|
|
|||
|
|
### 修改 1:类型比较忽略大小写 - [makecode.go](d:\work\hotimev1.5\code\makecode.go)
|
|||
|
|
|
|||
|
|
第 192 行,将 `info.GetString("type")` 转为小写再匹配:
|
|||
|
|
|
|||
|
|
```go
|
|||
|
|
if strings.Contains(strings.ToLower(info.GetString("type")), k) {
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
效果验证:
|
|||
|
|
|
|||
|
|
- `"BIGINT"` -> `"bigint"` -> contains `"int"` -> `"number"`
|
|||
|
|
- `"VARCHAR"` -> `"varchar"` -> contains `"char"` -> `"text"`
|
|||
|
|
- `"INT"` -> `"int"` -> contains `"int"` -> `"number"`
|
|||
|
|
- `"TIMESTAMP"` -> `"timestamp"` -> contains `"time"` -> `"time"`
|
|||
|
|
- `"DECIMAL"` -> `"decimal"` -> contains `"decimal"` -> `"number"`
|
|||
|
|
|
|||
|
|
### 修改 2:补充 DM 特有类型 - [config.go](d:\work\hotimev1.5\code\config.go)
|
|||
|
|
|
|||
|
|
在 `ColumnDataType` 中追加 DM 特有的数据类型,确保 CLOB、NUMBER 等也能被识别:
|
|||
|
|
|
|||
|
|
```go
|
|||
|
|
var ColumnDataType = map[string]string{
|
|||
|
|
// 现有 MySQL/SQLite 类型...
|
|||
|
|
// DM 特有类型
|
|||
|
|
"clob": "text",
|
|||
|
|
"number": "number",
|
|||
|
|
"numeric": "number",
|
|||
|
|
"binary": "text",
|
|||
|
|
"boolean": "number",
|
|||
|
|
"bit": "number",
|
|||
|
|
}
|
|||
|
|
```
|
|||
|
|
|