Skip to content
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
8 changes: 7 additions & 1 deletion go/vt/sqlparser/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,13 @@ func Preview(sql string) int {
case "delete":
return StmtDelete
}
switch strings.ToLower(trimmed) {
// For the following statements it is not sufficient to rely
// on loweredFirstWord. This is because they are not statements
// in the grammar and we are relying on Preview to parse them.
// For instance, we don't want: "BEGIN JUNK" to be parsed
// as StmtBegin.
trimmedNoComments, _ := SplitTrailingComments(trimmed)
switch strings.ToLower(trimmedNoComments) {
case "begin", "start transaction":
return StmtBegin
case "commit":
Expand Down
4 changes: 4 additions & 0 deletions go/vt/sqlparser/analyzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,13 @@ func TestPreview(t *testing.T) {
{"\n\t begin ", StmtBegin},
{"... begin ", StmtUnknown},
{"begin ...", StmtUnknown},
{"begin /* ... */", StmtBegin},
{"begin /* ... *//*test*/", StmtBegin},
{"start transaction", StmtBegin},
{"commit", StmtCommit},
{"commit /*...*/", StmtCommit},
{"rollback", StmtRollback},
{"rollback /*...*/", StmtRollback},
{"create", StmtDDL},
{"alter", StmtDDL},
{"rename", StmtDDL},
Expand Down