hanchuanchuan / goInception

一个集审核、执行、备份及生成回滚语句于一身的MySQL运维工具
https://hanchuanchuan.github.io/goInception/
GNU General Public License v3.0
1.59k stars 545 forks source link

int(5) 转 varchar(5) check 异常报错 #660

Open MzCqueF56s6Z opened 1 week ago

MzCqueF56s6Z commented 1 week ago

描述 表结构 CREATE TABLE test ( id int(5) DEFAULT NULL COMMENT 'test', ) check sql: ALTER TABLE test MODIFY COLUMN id varchar(4) default null COMMENT 'test' ;

runtime error: slice bounds out of range [:7] with capacity 6, goroutine 113 [running]: github.com/hanchuanchuan/goInception/server.(clientConn).Run.func1() /data/goInception/server/conn.go:420 +0x7b panic({0x17a0240?, 0xc0006c00f0?}) /app/go/src/runtime/panic.go:770 +0x132 github.com/hanchuanchuan/goInception/session.(session).checkModifyColumn(0xc000672008, 0xc0006b5a00, 0xc0072a3dc0) /data/goInception/session/session_inception.go:4115 /data/goInception/session/session_inception.go
有个字符串长度判断有问题 str := string([]byte(foundField.Type)[:7]) 此处 foundField.Type 为6:
int(5)

因没深入理解代码逻辑,采用这样的方式临时处理:

`

            str := ""    

            if len(foundField.Type) < 7 {    

                str = foundField.Type        

            } else {    

                str = foundField.Type[:7]    

            }    

`