mirror of
https://gitee.com/johng/gf
synced 2026-06-06 02:25:47 +08:00
由于 clickhouse 的 position的初始值为 1,导致gdb_core_utility.HasField 中对 fieldsArray 初始化出错 (#2346)
* 由于 clickhouse 的 position的初始值为 1,导致gdb_core_utility.HasField 中对 fieldsArray 初始化出错 * 修复单元测试 * 修复单元测试 * 补充单元测试 * 增加CK防御性代码 Co-authored-by: longl <longlei@dealmap.cloud> Co-authored-by: houseme <housemecn@gmail.com>
This commit is contained in:
@ -173,8 +173,12 @@ func (d *Driver) TableFields(
|
||||
isNull = true
|
||||
fieldType = fieldsResult[1]
|
||||
}
|
||||
position := m["position"].Int()
|
||||
if result[0]["position"].Int() != 0 {
|
||||
position -= 1
|
||||
}
|
||||
fields[m["name"].String()] = &gdb.TableField{
|
||||
Index: m["position"].Int(),
|
||||
Index: position,
|
||||
Name: m["name"].String(),
|
||||
Default: m["default_expression"].Val(),
|
||||
Comment: m["comment"].String(),
|
||||
|
||||
@ -533,18 +533,18 @@ func TestDriverClickhouse_TableFields(t *testing.T) {
|
||||
gtest.AssertNE(dataTypeTable, nil)
|
||||
|
||||
var result = map[string][]interface{}{
|
||||
"Col1": {1, "Col1", "UInt8", false, "", "", "", "列1"},
|
||||
"Col2": {2, "Col2", "String", true, "", "", "", "列2"},
|
||||
"Col3": {3, "Col3", "FixedString(3)", false, "", "", "", "列3"},
|
||||
"Col4": {4, "Col4", "String", false, "", "", "", "列4"},
|
||||
"Col5": {5, "Col5", "Map(String, UInt8)", false, "", "", "", "列5"},
|
||||
"Col6": {6, "Col6", "Array(String)", false, "", "", "", "列6"},
|
||||
"Col7": {7, "Col7", "Tuple(String, UInt8, Array(Map(String, String)))", false, "", "", "", "列7"},
|
||||
"Col8": {8, "Col8", "DateTime", false, "", "", "", "列8"},
|
||||
"Col9": {9, "Col9", "UUID", false, "", "", "", "列9"},
|
||||
"Col10": {10, "Col10", "DateTime", false, "", "", "", "列10"},
|
||||
"Col11": {11, "Col11", "Decimal(9, 2)", false, "", "", "", "列11"},
|
||||
"Col12": {12, "Col12", "Decimal(9, 2)", false, "", "", "", "列12"},
|
||||
"Col1": {0, "Col1", "UInt8", false, "", "", "", "列1"},
|
||||
"Col2": {1, "Col2", "String", true, "", "", "", "列2"},
|
||||
"Col3": {2, "Col3", "FixedString(3)", false, "", "", "", "列3"},
|
||||
"Col4": {3, "Col4", "String", false, "", "", "", "列4"},
|
||||
"Col5": {4, "Col5", "Map(String, UInt8)", false, "", "", "", "列5"},
|
||||
"Col6": {5, "Col6", "Array(String)", false, "", "", "", "列6"},
|
||||
"Col7": {6, "Col7", "Tuple(String, UInt8, Array(Map(String, String)))", false, "", "", "", "列7"},
|
||||
"Col8": {7, "Col8", "DateTime", false, "", "", "", "列8"},
|
||||
"Col9": {8, "Col9", "UUID", false, "", "", "", "列9"},
|
||||
"Col10": {9, "Col10", "DateTime", false, "", "", "", "列10"},
|
||||
"Col11": {10, "Col11", "Decimal(9, 2)", false, "", "", "", "列11"},
|
||||
"Col12": {11, "Col12", "Decimal(9, 2)", false, "", "", "", "列12"},
|
||||
}
|
||||
for k, v := range result {
|
||||
_, ok := dataTypeTable[k]
|
||||
@ -558,3 +558,13 @@ func TestDriverClickhouse_TableFields(t *testing.T) {
|
||||
gtest.AssertEQ(dataTypeTable[k].Comment, v[7])
|
||||
}
|
||||
}
|
||||
|
||||
func TestDriverClickhouse_TableFields_HasField(t *testing.T) {
|
||||
connect := clickhouseConfigDB()
|
||||
gtest.AssertNil(createClickhouseExampleTable(connect))
|
||||
defer dropClickhouseExampleTable(connect)
|
||||
// 未修复前:panic: runtime error: index out of range [12] with length 12
|
||||
b, err := connect.GetCore().HasField(context.Background(), "data_type", "Col1")
|
||||
gtest.AssertNil(err)
|
||||
gtest.AssertEQ(b, true)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user