Skip to content

Commit

Permalink
fix: ignore empty parts in multistatement queries (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
stepansergeevitch authored Jun 19, 2024
1 parent ad53156 commit e3a3380
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 3 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ func SplitStatements(sql string) ([]string, error) {
if err != nil {
return nil, ConstructNestedError("error during splitting query", err)
}
if strings.Trim(query, " \t\n") == "" {
continue
}
queries = append(queries, query)
}

Expand Down
3 changes: 2 additions & 1 deletion utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,9 @@ func runSplitStatement(t *testing.T, value string, expected []string) {
func TestSplitStatements(t *testing.T) {
runSplitStatement(t, "SELECT 1; SELECT 2;", []string{"SELECT 1", " SELECT 2"})
runSplitStatement(t, "SELECT 1;", []string{"SELECT 1"})
runSplitStatement(t, "SELECT 1; ", []string{"SELECT 1"})
runSplitStatement(t, "SELECT 1", []string{"SELECT 1"})
runSplitStatement(t, "SELECT 1; ; ; ; ", []string{"SELECT 1", " ", " ", " ", " "})
runSplitStatement(t, "SELECT 1; ; ; ; ", []string{"SELECT 1"})

runSplitStatement(t, "SET time_zone=America/New_York; SELECT 2 /*some ; comment*/", []string{"SET time_zone=America/New_York", " SELECT 2 /*some ; comment*/"})
runSplitStatement(t, "SET time_zone='America/New_York'; SELECT 2 /*some ; comment*/", []string{"SET time_zone='America/New_York'", " SELECT 2 /*some ; comment*/"})
Expand Down

0 comments on commit e3a3380

Please sign in to comment.