-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ddl: enhance validation of column names when creating table #6349
Changes from 2 commits
15ae503
0415a4c
6af644b
6ff30ae
1897d89
c341358
51863b8
3c4c4bc
62a825e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -536,6 +536,16 @@ func checkTooManyColumns(colDefs []*ast.ColumnDef) error { | |
return nil | ||
} | ||
|
||
// checkContainDotColumns check field contains the table name. | ||
func checkContainDotColumns(tableName string, colDefs []*ast.ColumnDef) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we check it in the function of |
||
for _, colDef := range colDefs { | ||
if colDef.Name.Table.O != tableName && len(colDef.Name.Table.O) != 0 { | ||
return ErrWrongTableName.GenByArgs(colDef.Name.Table.O) | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func checkDuplicateConstraint(namesMap map[string]bool, name string, foreign bool) error { | ||
if name == "" { | ||
return nil | ||
|
@@ -784,6 +794,10 @@ func (d *ddl) CreateTable(ctx sessionctx.Context, s *ast.CreateTableStmt) (err e | |
return errors.Trace(err) | ||
} | ||
|
||
if err = checkContainDotColumns(ident.Name.O, colDefs); err != nil { | ||
return errors.Trace(err) | ||
} | ||
|
||
cols, newConstraints, err := buildColumnsAndConstraints(ctx, colDefs, s.Constraints) | ||
if err != nil { | ||
return errors.Trace(err) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2515,6 +2515,15 @@ func (s *testSuite) TestIssue5341(c *C) { | |
tk.MustQuery("select * from test.t where a < 1 order by a limit 0;").Check(testkit.Rows()) | ||
} | ||
|
||
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)") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add test for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Already add. |
||
} | ||
|
||
func (s *testSuite) TestCheckIndex(c *C) { | ||
s.ctx = mock.NewContext() | ||
s.ctx.Store = s.store | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/check/checks