Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into merge-loop
Browse files Browse the repository at this point in the history
  • Loading branch information
D3Hunter committed Jan 9, 2024
2 parents dd3c7ec + 75aa3c7 commit c681cb1
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 8 deletions.
11 changes: 11 additions & 0 deletions pkg/parser/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ func isIdentExtend(ch byte) bool {
return ch >= 0x80
}

// See https://dev.mysql.com/doc/refman/5.7/en/identifiers.html
func isInCorrectIdentifierName(name string) bool {
if len(name) == 0 {
return true
}
if name[len(name)-1] == ' ' {
return true
}
return false
}

// Initialize a lookup table for isUserVarChar
var isUserVarCharTable [256]bool

Expand Down
7 changes: 6 additions & 1 deletion pkg/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -18696,7 +18696,12 @@ yynewstate:
}
case 1607:
{
parser.yyVAL.item = &ast.TableName{Schema: model.NewCIStr(yyS[yypt-2].ident), Name: model.NewCIStr(yyS[yypt-0].ident)}
schema := yyS[yypt-2].ident
if isInCorrectIdentifierName(schema) {
yylex.AppendError(ErrWrongDBName.GenWithStackByArgs(schema))
return 1
}
parser.yyVAL.item = &ast.TableName{Schema: model.NewCIStr(schema), Name: model.NewCIStr(yyS[yypt-0].ident)}
}
case 1608:
{
Expand Down
7 changes: 6 additions & 1 deletion pkg/parser/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -8788,7 +8788,12 @@ TableName:
}
| Identifier '.' Identifier
{
$$ = &ast.TableName{Schema: model.NewCIStr($1), Name: model.NewCIStr($3)}
schema := $1
if isInCorrectIdentifierName(schema) {
yylex.AppendError(ErrWrongDBName.GenWithStackByArgs(schema))
return 1
}
$$ = &ast.TableName{Schema: model.NewCIStr(schema), Name: model.NewCIStr($3)}
}
| '*' '.' Identifier
{
Expand Down
6 changes: 6 additions & 0 deletions pkg/parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3961,6 +3961,12 @@ func TestErrorMsg(t *testing.T) {
_, _, err = p.Parse("create table t(f_year year(5))ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;", "", "")
require.EqualError(t, err, "[parser:1818]Supports only YEAR or YEAR(4) column")

_, _, err = p.Parse("create table ``.t (id int);", "", "")
require.EqualError(t, err, "[parser:1102]Incorrect database name ''")

_, _, err = p.Parse("create table ` `.t (id int);", "", "")
require.EqualError(t, err, "[parser:1102]Incorrect database name ' '")

_, _, err = p.Parse("select ifnull(a,0) & ifnull(a,0) like '55' ESCAPE '\\\\a' from t;", "", "")
require.EqualError(t, err, "[parser:1210]Incorrect arguments to ESCAPE")

Expand Down
2 changes: 2 additions & 0 deletions pkg/parser/yy_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ var (
ErrWarnDeprecatedSyntaxNoReplacement = terror.ClassParser.NewStd(mysql.ErrWarnDeprecatedSyntaxNoReplacement)
// ErrWrongUsage returns for incorrect usages.
ErrWrongUsage = terror.ClassParser.NewStd(mysql.ErrWrongUsage)
// ErrWrongDBName returns for incorrect DB name.
ErrWrongDBName = terror.ClassParser.NewStd(mysql.ErrWrongDBName)
// SpecFieldPattern special result field pattern
SpecFieldPattern = regexp.MustCompile(`(\/\*!(M?[0-9]{5,6})?|\*\/)`)
specCodeStart = regexp.MustCompile(`^\/\*!(M?[0-9]{5,6})?[ \t]*`)
Expand Down
13 changes: 7 additions & 6 deletions pkg/store/mockstore/mockstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,13 @@ func NewMockStore(options ...MockTiKVStoreOption) (kv.Storage, error) {
case MockTiKV:
store, err = newMockTikvStore(&opt)
case EmbedUnistore:
if opt.path == "" && len(options) == 0 && ImageAvailable() {
// Create the store from the image.
if path, err := copyImage(); err == nil {
opt.path = path
}
}
// Don't do this unless we figure out why the test image does not accelerate out unit tests.
// if opt.path == "" && len(options) == 0 && ImageAvailable() {
// // Create the store from the image.
// if path, err := copyImage(); err == nil {
// opt.path = path
// }
// }

store, err = newUnistore(&opt)
default:
Expand Down

0 comments on commit c681cb1

Please sign in to comment.