Skip to content

Commit

Permalink
Merge pull request pingcap#117 from pingcap/shenli/set-charset
Browse files Browse the repository at this point in the history
parser: Charset name can be string literal
  • Loading branch information
qiuyesuifeng committed Sep 11, 2015
2 parents 341785e + 811e4b9 commit 9d7e50c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
12 changes: 11 additions & 1 deletion parser/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,17 @@ CharsetName:
Identifier
{
c := strings.ToLower($1.(string))
if charset.ValidCharsetAndCollation(c, "") {
if charset.ValidCharsetAndCollation(c, "") {
$$ = c
} else {
yylex.(*lexer).err("", fmt.Sprintf("Unknown character set: '%s'", $1.(string)))
return 1
}
}
| stringLit
{
c := strings.ToLower($1.(string))
if charset.ValidCharsetAndCollation(c, "") {
$$ = c
} else {
yylex.(*lexer).err("", fmt.Sprintf("Unknown character set: '%s'", $1.(string)))
Expand Down
3 changes: 3 additions & 0 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ func (s *testParserSuite) TestParser0(c *C) {
// global system variables
{"SET GLOBAL autocommit = 1", true},
{"SET @@global.autocommit = 1", true},
// SET CHARACTER SET
{"SET CHARACTER SET utf8mb4;", true},
{"SET CHARACTER SET 'utf8mb4';", true},

// qualified select
{"SELECT a.b.c FROM t", true},
Expand Down

0 comments on commit 9d7e50c

Please sign in to comment.