Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ciscoxll committed Apr 25, 2018
1 parent 6af644b commit 6ff30ae
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
6 changes: 6 additions & 0 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2517,11 +2517,17 @@ func (s *testSuite) TestIssue5341(c *C) {

func (s *testSuite) TestContainDotColumn(c *C) {
tk := testkit.NewTestKit(c, s.store)

tk.MustExec("use test")
tk.MustExec("drop table if exists test.t1")
tk.MustExec("create table test.t1(t1.a char)")
tk.MustExec("drop table if exists t2")
tk.MustExec("create table t2(a char, t2.b int)")

tk.MustExec("drop table if exists t3")
_, err := tk.Exec("create table t3(s.a char);")
terr := errors.Trace(err).(*errors.Err).Cause().(*terror.Error)
c.Assert(terr.Code(), Equals, terror.ErrCode(mysql.ErrWrongTableName))
}

func (s *testSuite) TestCheckIndex(c *C) {
Expand Down
21 changes: 9 additions & 12 deletions plan/preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func (p *preprocessor) Enter(in ast.Node) (out ast.Node, skipChildren bool) {
case *ast.CreateTableStmt:
p.inCreateOrDropTable = true
p.checkCreateTableGrammar(node)
p.checkContainDotColumn(node)
case *ast.DropTableStmt:
p.inCreateOrDropTable = true
p.checkDropTableGrammar(node)
Expand Down Expand Up @@ -223,12 +224,6 @@ func (p *preprocessor) checkCreateTableGrammar(stmt *ast.CreateTableStmt) {
p.err = ddl.ErrWrongTableName.GenByArgs(tName)
return
}

if tableName, ok := checksContainDotColumns(tName, stmt.Cols); ok {
p.err = ddl.ErrWrongTableName.GenByArgs(tableName)
return
}

countPrimaryKey := 0
for _, colDef := range stmt.Cols {
if err := checkColumn(colDef); err != nil {
Expand Down Expand Up @@ -467,14 +462,16 @@ func isIncorrectName(name string) bool {
return false
}

// checksContainDotColumns check field contains the table name.
func checksContainDotColumns(tableName string, colDefs []*ast.ColumnDef) (string, bool) {
for _, colDef := range colDefs {
if colDef.Name.Table.O != tableName && len(colDef.Name.Table.O) != 0 {
return colDef.Name.Table.O, true
// checkContainDotColumn checks field contains the table name.
// for example :create table t (c1.c2 int default null).
func (p *preprocessor) checkContainDotColumn(stmt *ast.CreateTableStmt) {
tName := stmt.Table.Name.String()
for _, colDef := range stmt.Cols {
// check table name.
if colDef.Name.Table.O != tName && len(colDef.Name.Table.O) != 0 {
p.err = ddl.ErrWrongTableName.GenByArgs(colDef.Name.Table.O)
}
}
return "", false
}

func (p *preprocessor) handleTableName(tn *ast.TableName) {
Expand Down

0 comments on commit 6ff30ae

Please sign in to comment.