Skip to content

Commit

Permalink
判断字符数据类型的默认值是否超过定义的长度
Browse files Browse the repository at this point in the history
  • Loading branch information
leonadle committed Oct 13, 2023
1 parent 5deb6c6 commit 7bf8c9e
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions controllers/process/column.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,13 @@ func (c *ColOptions) CheckColumnDefaultValue() error {
return fmt.Errorf("列`%s`默认值和类型不匹配[表`%s`]", c.Column, c.Table)
}
}
case mysql.TypeVarchar, mysql.TypeString:
// 判断string型默认值的长度是否超过了定义的长度
if utf8.RuneCountInString(c.DefaultValue.(string)) > c.Flen {
return fmt.Errorf("列`%s`的默认值超过了字段类型定义的长度[表`%s`]", c.Column, c.Table)
}
}

}
// 有默认值,配置了无效的默认值,如default current_timestamp
if c.HasDefaultValue && !(c.Tp == mysql.TypeTimestamp || c.Tp == mysql.TypeDatetime) && c.DefaultValue == "current_timestamp" {
Expand Down

0 comments on commit 7bf8c9e

Please sign in to comment.