Skip to content

Commit

Permalink
Fix bug where table name is not properly collected on drop statement
Browse files Browse the repository at this point in the history
  • Loading branch information
lu-zhengda committed May 15, 2024
1 parent a0ba802 commit 77f9b0d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
11 changes: 11 additions & 0 deletions normalizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,17 @@ multiline comment */
Size: 11,
},
},
{
input: `DROP TABLE IF EXISTS users`,
expected: `DROP TABLE IF EXISTS users`,
statementMetadata: StatementMetadata{
Tables: []string{"users"},
Comments: []string{},
Commands: []string{"DROP"},
Procedures: []string{},
Size: 9,
},
},
}

normalizer := NewNormalizer(
Expand Down
15 changes: 15 additions & 0 deletions sqllexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,21 @@ func TestLexer(t *testing.T) {
},
lexerOpts: []lexerOption{WithDBMS(DBMSMySQL)},
},
{
name: "drop table if exists",
input: `DROP TABLE IF EXISTS users`,
expected: []Token{
{IDENT, "DROP"},
{WS, " "},
{IDENT, "TABLE"},
{WS, " "},
{IDENT, "IF"},
{WS, " "},
{IDENT, "EXISTS"},
{WS, " "},
{IDENT, "users"},
},
},
}

for _, tt := range tests {
Expand Down
2 changes: 2 additions & 0 deletions sqllexer_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ var tableIndicators = map[string]bool{
"INTO": true,
"UPDATE": true,
"TABLE": true,
"EXISTS": true, // Drop Table If Exists
"STRAIGHT_JOIN": true, // MySQL
"CLONE": true, // Snowflake
}
Expand Down Expand Up @@ -145,6 +146,7 @@ var keywords = map[string]bool{
"OFFSET": true,
"OF": true,
"SKIP": true,
"IF": true,
}

func isWhitespace(ch rune) bool {
Expand Down

0 comments on commit 77f9b0d

Please sign in to comment.