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

ddl: refine error messages in unsupported column options #11065

Merged
merged 7 commits into from
Jul 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions ddl/db_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,33 @@ func (s *testIntegrationSuite4) TestChangingTableCharset(c *C) {

}

func (s *testIntegrationSuite5) 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 *testIntegrationSuite2) TestCaseInsensitiveCharsetAndCollate(c *C) {
tk := testkit.NewTestKit(c, s.store)

Expand Down
16 changes: 11 additions & 5 deletions ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -2520,9 +2520,14 @@ func processColumnOptions(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 @@ -2604,11 +2609,12 @@ 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 = processColumnOptions(ctx, newCol, specNewColumn.Options); err != nil {
return nil, errors.Trace(err)
}
if err = processColumnOptions(ctx, newCol, specNewColumn.Options); err != nil {

if err = modifiable(&col.FieldType, &newCol.FieldType); err != nil {
return nil, errors.Trace(err)
}

Expand Down