Skip to content

Commit ffe55b8

Browse files
tangentazz-jason
authored andcommitted
ddl: refine error messages in unsupported column options (#110… (#11274)
1 parent a52cfff commit ffe55b8

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

ddl/db_integration_test.go

+27
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,33 @@ func (s *testIntegrationSuite10) TestChangingTableCharset(c *C) {
782782

783783
}
784784

785+
func (s *testIntegrationSuite5) TestModifyingColumnOption(c *C) {
786+
tk := testkit.NewTestKit(c, s.store)
787+
tk.MustExec("create database if not exists test")
788+
tk.MustExec("use test")
789+
790+
errMsg := "[ddl:203]" // unsupported modify column with references
791+
assertErrCode := func(sql string, errCodeStr string) {
792+
_, err := tk.Exec(sql)
793+
c.Assert(err, NotNil)
794+
c.Assert(err.Error()[:len(errCodeStr)], Equals, errCodeStr)
795+
}
796+
797+
tk.MustExec("drop table if exists t1")
798+
tk.MustExec("create table t1 (b char(1) default null) engine=InnoDB default charset=utf8mb4 collate=utf8mb4_general_ci")
799+
tk.MustExec("alter table t1 modify column b char(1) character set utf8mb4 collate utf8mb4_general_ci")
800+
801+
tk.MustExec("drop table t1")
802+
tk.MustExec("create table t1 (b char(1) collate utf8mb4_general_ci)")
803+
tk.MustExec("alter table t1 modify b char(1) character set utf8mb4 collate utf8mb4_general_ci")
804+
805+
tk.MustExec("drop table t1")
806+
tk.MustExec("drop table if exists t2")
807+
tk.MustExec("create table t1 (a int)")
808+
tk.MustExec("create table t2 (b int, c int)")
809+
assertErrCode("alter table t2 modify column c int references t1(a)", errMsg)
810+
}
811+
785812
func (s *testIntegrationSuite7) TestCaseInsensitiveCharsetAndCollate(c *C) {
786813
tk := testkit.NewTestKit(c, s.store)
787814

ddl/ddl_api.go

+11-5
Original file line numberDiff line numberDiff line change
@@ -2440,9 +2440,14 @@ func processColumnOptions(ctx sessionctx.Context, col *table.Column, options []*
24402440
for _, colName := range findColumnNamesInExpr(opt.Expr) {
24412441
col.Dependences[colName.Name.L] = struct{}{}
24422442
}
2443+
case ast.ColumnOptionCollate:
2444+
col.Collate = opt.StrValue
2445+
case ast.ColumnOptionReference:
2446+
return errors.Trace(errUnsupportedModifyColumn.GenWithStackByArgs("with references"))
2447+
case ast.ColumnOptionFulltext:
2448+
return errors.Trace(errUnsupportedModifyColumn.GenWithStackByArgs("with full text"))
24432449
default:
2444-
// TODO: Support other types.
2445-
return errors.Trace(errUnsupportedModifyColumn.GenWithStackByArgs(opt.Tp))
2450+
return errors.Trace(errUnsupportedModifyColumn.GenWithStackByArgs(fmt.Sprintf("unknown column option type: %d", opt.Tp)))
24462451
}
24472452
}
24482453

@@ -2524,11 +2529,12 @@ func (d *ddl) getModifiableColumnJob(ctx sessionctx.Context, ident ast.Ident, or
25242529
if err != nil {
25252530
return nil, errors.Trace(err)
25262531
}
2527-
err = modifiable(&col.FieldType, &newCol.FieldType)
2528-
if err != nil {
2532+
2533+
if err = processColumnOptions(ctx, newCol, specNewColumn.Options); err != nil {
25292534
return nil, errors.Trace(err)
25302535
}
2531-
if err = processColumnOptions(ctx, newCol, specNewColumn.Options); err != nil {
2536+
2537+
if err = modifiable(&col.FieldType, &newCol.FieldType); err != nil {
25322538
return nil, errors.Trace(err)
25332539
}
25342540

0 commit comments

Comments
 (0)