Skip to content

Commit

Permalink
update: 优化alter table modify/change子句的关键字审核逻辑(#392)
Browse files Browse the repository at this point in the history
  • Loading branch information
hanchuanchuan committed Oct 16, 2021
1 parent d896e9b commit 2af1851
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion session/session_inception.go
Expand Up @@ -2727,6 +2727,7 @@ func (s *session) checkCreateTable(node *ast.CreateTableStmt, sql string) {
onUpdateDatetimeCount := 0

for _, field := range node.Cols {
s.checkKeyWords(field.Name.Name.O)
s.mysqlCheckField(table, field)
for _, op := range field.Options {
switch op.Tp {
Expand Down Expand Up @@ -3936,7 +3937,7 @@ func (s *session) mysqlCheckField(t *TableInfo, field *ast.ColumnDef) {
s.appendErrorNo(ErrFloatDoubleToDecimal, field.Name.Name)
}

s.checkKeyWords(field.Name.Name.O)
// s.checkKeyWords(field.Name.Name.O)

// notNullFlag := mysql.HasNotNullFlag(field.Tp.Flag)
// autoIncrement := mysql.HasAutoIncrementFlag(field.Tp.Flag)
Expand Down Expand Up @@ -4415,6 +4416,7 @@ func (s *session) checkAddColumn(t *TableInfo, c *ast.AlterTableSpec) {
if found {
s.appendErrorNo(ER_COLUMN_EXISTED, fmt.Sprintf("%s.%s", t.Name, nc.Name.Name))
} else {
s.checkKeyWords(nc.Name.Name.O)
s.mysqlCheckField(t, nc)

if !s.hasError() {
Expand Down
12 changes: 12 additions & 0 deletions session/session_inception_test.go
Expand Up @@ -1398,6 +1398,11 @@ func (s *testSessionIncSuite) TestAlterTableModifyColumn(c *C) {

sql = "alter table t1 modify c1 int not null;alter table t1 add primary key(id,c1);"
s.testErrorCode(c, sql)

config.GetGlobalConfig().Inc.EnableIdentiferKeyword = false
s.mustRunExec(c, "drop table if exists t1;create table t1(id int not null,`alter` int);")
sql = "alter table t1 modify `alter` bigint;"
s.testErrorCode(c, sql)
}

func (s *testSessionIncSuite) TestAlterTableChangeColumn(c *C) {
Expand All @@ -1417,6 +1422,13 @@ func (s *testSessionIncSuite) TestAlterTableChangeColumn(c *C) {

config.GetGlobalConfig().Inc.EnableChangeColumn = true

config.GetGlobalConfig().Inc.EnableIdentiferKeyword = false
s.mustRunExec(c, "drop table if exists t1;create table t1(id int not null,`alter` int);")
sql = "alter table t1 change `alter` `alter` bigint;"
s.testErrorCode(c, sql)
sql = "alter table t1 change `alter` `delete` bigint;"
s.testErrorCode(c, sql,
session.NewErr(session.ER_IDENT_USE_KEYWORD, "delete"))
}

func (s *testSessionIncSuite) TestAlterTableDropColumn(c *C) {
Expand Down

0 comments on commit 2af1851

Please sign in to comment.