Skip to content
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

parser: support of character in create table statement #7378

Merged
merged 4 commits into from
Aug 13, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions parser/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -6094,6 +6094,17 @@ StringType:
}
$$ = x
}
| "NATIONAL" "CHARACTER" FieldLen OptBinary OptCollate
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we define a new parser rule like:

CharOrCharacter:
     "CHAR" | "CHARACTER"

Then we could merge this into the first branch.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shenli
NationalOpt could be empty, "CHAR(10)" is legal, but "CHARACTER(10)" is illegal in MySQL. There must be a "NATIONAL" before "CHARACTER".

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

{
x := types.NewFieldType(mysql.TypeString)
x.Flen = $3.(int)
x.Charset = $4.(*ast.OptBinary).Charset
x.Collate = $5.(string)
if $4.(*ast.OptBinary).IsBinary {
x.Flag |= mysql.BinaryFlag
}
$$ = x
}
| Varchar FieldLen OptBinary OptCollate
{
x := types.NewFieldType(mysql.TypeVarchar)
Expand Down
6 changes: 6 additions & 0 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,12 @@ func (s *testParserSuite) TestSimple(c *C) {
_, err = parser.ParseOneStmt(src, "", "")
c.Assert(err, IsNil)

// for #7371, support NATIONAL CHARACTER
// reference link: https://dev.mysql.com/doc/refman/5.7/en/charset-national.html
src = "CREATE TABLE t(c1 NATIONAL CHARACTER(10));"
_, err = parser.ParseOneStmt(src, "", "")
c.Assert(err, IsNil)

src = `CREATE TABLE t(a tinyint signed,
b smallint signed,
c mediumint signed,
Expand Down