Skip to content

Commit

Permalink
ddl: refine error messages in unsupported column options pingcap#11065
Browse files Browse the repository at this point in the history
  • Loading branch information
tangenta committed Jul 19, 2019
1 parent 2fe5636 commit b6b5a6b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
27 changes: 27 additions & 0 deletions ddl/db_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,33 @@ func (s *testIntegrationSuite) TestChangingTableCharset(c *C) {

}

func (s *testIntegrationSuite) TestModifyingColumnOption(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("create database if not exists test")
tk.MustExec("use test")

errMsg := "[ddl:203]" // unsupported modify column with references
assertErrCode := func(sql string, errCodeStr string) {
_, err := tk.Exec(sql)
c.Assert(err, NotNil)
c.Assert(err.Error()[:len(errCodeStr)], Equals, errCodeStr)
}

tk.MustExec("drop table if exists t1")
tk.MustExec("create table t1 (b char(1) default null) engine=InnoDB default charset=utf8mb4 collate=utf8mb4_general_ci")
tk.MustExec("alter table t1 modify column b char(1) character set utf8mb4 collate utf8mb4_general_ci")

tk.MustExec("drop table t1")
tk.MustExec("create table t1 (b char(1) collate utf8mb4_general_ci)")
tk.MustExec("alter table t1 modify b char(1) character set utf8mb4 collate utf8mb4_general_ci")

tk.MustExec("drop table t1")
tk.MustExec("drop table if exists t2")
tk.MustExec("create table t1 (a int)")
tk.MustExec("create table t2 (b int, c int)")
assertErrCode("alter table t2 modify column c int references t1(a)", errMsg)
}

func (s *testIntegrationSuite) TestCaseInsensitiveCharsetAndCollate(c *C) {
tk := testkit.NewTestKit(c, s.store)

Expand Down
14 changes: 9 additions & 5 deletions ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1940,9 +1940,14 @@ func setDefaultAndComment(ctx sessionctx.Context, col *table.Column, options []*
for _, colName := range findColumnNamesInExpr(opt.Expr) {
col.Dependences[colName.Name.L] = struct{}{}
}
case ast.ColumnOptionCollate:
col.Collate = opt.StrValue
case ast.ColumnOptionReference:
return errors.Trace(errUnsupportedModifyColumn.GenWithStackByArgs("with references"))
case ast.ColumnOptionFulltext:
return errors.Trace(errUnsupportedModifyColumn.GenWithStackByArgs("with full text"))
default:
// TODO: Support other types.
return errors.Trace(errUnsupportedModifyColumn.GenWithStackByArgs(opt.Tp))
return errors.Trace(errUnsupportedModifyColumn.GenWithStackByArgs(fmt.Sprintf("unknown column option type: %d", opt.Tp)))
}
}

Expand Down Expand Up @@ -2024,11 +2029,10 @@ func (d *ddl) getModifiableColumnJob(ctx sessionctx.Context, ident ast.Ident, or
if err != nil {
return nil, errors.Trace(err)
}
err = modifiable(&col.FieldType, &newCol.FieldType)
if err != nil {
if err = setDefaultAndComment(ctx, newCol, specNewColumn.Options); err != nil {
return nil, errors.Trace(err)
}
if err = setDefaultAndComment(ctx, newCol, specNewColumn.Options); err != nil {
if err = modifiable(&col.FieldType, &newCol.FieldType); err != nil {
return nil, errors.Trace(err)
}

Expand Down

0 comments on commit b6b5a6b

Please sign in to comment.