plan: check empty table name in RenameTableStmt (#6383)
This commit is contained in:
@ -57,6 +57,7 @@ func (p *preprocessor) Enter(in ast.Node) (out ast.Node, skipChildren bool) {
|
||||
p.checkDropTableGrammar(node)
|
||||
case *ast.RenameTableStmt:
|
||||
p.inCreateOrDropTable = true
|
||||
p.checkRenameTableGrammar(node)
|
||||
case *ast.CreateIndexStmt:
|
||||
p.checkCreateIndexGrammar(node)
|
||||
case *ast.AlterTableStmt:
|
||||
@ -300,6 +301,21 @@ func (p *preprocessor) checkCreateIndexGrammar(stmt *ast.CreateIndexStmt) {
|
||||
p.err = checkIndexInfo(stmt.IndexName, stmt.IndexColNames)
|
||||
}
|
||||
|
||||
func (p *preprocessor) checkRenameTableGrammar(stmt *ast.RenameTableStmt) {
|
||||
oldTable := stmt.OldTable.Name.String()
|
||||
newTable := stmt.NewTable.Name.String()
|
||||
|
||||
if isIncorrectName(oldTable) {
|
||||
p.err = ddl.ErrWrongTableName.GenByArgs(oldTable)
|
||||
return
|
||||
}
|
||||
|
||||
if isIncorrectName(newTable) {
|
||||
p.err = ddl.ErrWrongTableName.GenByArgs(newTable)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (p *preprocessor) checkAlterTableGrammar(stmt *ast.AlterTableStmt) {
|
||||
tName := stmt.Table.Name.String()
|
||||
if isIncorrectName(tName) {
|
||||
|
||||
@ -134,6 +134,8 @@ func (s *testValidatorSuite) TestValidator(c *C) {
|
||||
{"alter table t change column a `a ` int", true, errors.New("[ddl:1166]Incorrect column name 'a '")},
|
||||
{"create index idx on `t ` (a)", true, errors.New("[ddl:1103]Incorrect table name 't '")},
|
||||
{"create index idx on `` (a)", true, errors.New("[ddl:1103]Incorrect table name ''")},
|
||||
{"rename table t to ``", false, errors.New("[ddl:1103]Incorrect table name ''")},
|
||||
{"rename table `` to t", false, errors.New("[ddl:1103]Incorrect table name ''")},
|
||||
|
||||
// issue 3844
|
||||
{`create table t (a set("a, b", "c, d"))`, true, errors.New("[types:1367]Illegal set 'a, b' value found during parsing")},
|
||||
|
||||
Reference in New Issue
Block a user