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: reset lexer.identifierDot correctly when reusing parsers (#45903) #45910

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions parser/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ func (s *Scanner) reset(sql string) {
s.stmtStartPos = 0
s.inBangComment = false
s.lastKeyword = 0
s.identifierDot = false
}

func (s *Scanner) stmtText() string {
Expand Down
12 changes: 12 additions & 0 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7269,6 +7269,18 @@ func TestTTLTableOption(t *testing.T) {
RunTest(t, table, false)
}

func TestIssue45898(t *testing.T) {
p := parser.New()
p.ParseSQL("a.")
stmts, _, err := p.ParseSQL("select count(1) from t")
require.NoError(t, err)
var sb strings.Builder
restoreCtx := NewRestoreCtx(DefaultRestoreFlags, &sb)
sb.Reset()
stmts[0].Restore(restoreCtx)
require.Equal(t, "SELECT COUNT(1) FROM `t`", sb.String())
}

func TestMultiStmt(t *testing.T) {
p := parser.New()
stmts, _, err := p.Parse("SELECT 'foo'; SELECT 'foo;bar','baz'; select 'foo' , 'bar' , 'baz' ;select 1", "", "")
Expand Down