planner/core: add a range check against display width of BIT column type (#11942)

This commit is contained in:
Tanner
2019-09-02 17:19:31 +08:00
committed by GitHub
parent 2a155f4eaf
commit cfef1bc52f
5 changed files with 36 additions and 5 deletions

View File

@ -59,3 +59,24 @@ func (s *testIntegrationSuite) TestShowSubquery(c *C) {
"a varchar(10) YES <nil> ",
))
}
func (s *testIntegrationSuite) BitColErrorMessage(c *C) {
store, dom, err := newStoreWithBootstrap()
c.Assert(err, IsNil)
tk := testkit.NewTestKit(c, store)
defer func() {
dom.Close()
store.Close()
}()
tk.MustExec("use test")
tk.MustExec("drop table if exists bit_col_t")
tk.MustExec("create table bit_col_t (a bit(64))")
tk.MustExec("drop table bit_col_t")
tk.MustExec("create table bit_col_t (a bit(1))")
tk.MustExec("drop table bit_col_t")
_, err = tk.Exec("create table bit_col_t (a bit(0))")
c.Assert(err, NotNil)
_, err = tk.Exec("create table bit_col_t (a bit(65))")
c.Assert(err, NotNil)
}

View File

@ -628,13 +628,20 @@ func checkColumn(colDef *ast.ColumnDef) error {
if tp.Flen > mysql.MaxDecimalWidth {
return types.ErrTooBigPrecision.GenWithStackByArgs(tp.Flen, colDef.Name.Name.O, mysql.MaxDecimalWidth)
}
case mysql.TypeBit:
if tp.Flen <= 0 {
return types.ErrInvalidFieldSize.GenWithStackByArgs(colDef.Name.Name.O)
}
if tp.Flen > mysql.MaxBitDisplayWidth {
return types.ErrTooBigDisplayWidth.GenWithStackByArgs(colDef.Name.Name.O, mysql.MaxBitDisplayWidth)
}
default:
// TODO: Add more types.
}
return nil
}
// isDefaultValNowSymFunc checks whether defaul value is a NOW() builtin function.
// isDefaultValNowSymFunc checks whether default value is a NOW() builtin function.
func isDefaultValNowSymFunc(expr ast.ExprNode) bool {
if funcCall, ok := expr.(*ast.FuncCallExpr); ok {
// Default value NOW() is transformed to CURRENT_TIMESTAMP() in parser.