Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
MzCqueF56s6Z opened this issue Jun 28, 2024 · 0 comments
Open

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

MzCqueF56s6Z opened this issue Jun 28, 2024 · 0 comments

Comments

@MzCqueF56s6Z
Copy link

MzCqueF56s6Z commented Jun 28, 2024

描述
表结构
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]    

            }    

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant