plan: check empty table name in RenameTableStmt (#6383)

This commit is contained in:
winkyao
2018-04-26 11:07:25 +08:00
committed by GitHub
parent 530aa9519d
commit 2ecd406e59
2 changed files with 18 additions and 0 deletions

View File

@ -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) {

View File

@ -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")},