From fdd234ee2a8a5ce63066629b77d573707d325fea Mon Sep 17 00:00:00 2001 From: Flavio Piccinelli Date: Thu, 3 Apr 2025 20:47:17 +0200 Subject: [PATCH] Fix handling of `stateSep` in batch package. Addresses bug #247 --- batch/batch.go | 7 +++++++ batch/batch_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/batch/batch.go b/batch/batch.go index 5b793dcb..7c23241e 100644 --- a/batch/batch.go +++ b/batch/batch.go @@ -123,6 +123,13 @@ func stateSep(l *lexer) stateFn { return nil } s := l.Sql[l.At+len(l.Sep):] + if unicode.IsLetter(rune(s[0])) { + // If the first character after the separator is a letter, then + // it's a text line that happens to start with the separator. + // E.g. statement "goto", column name "gone", etc. + // We don't want to split here. + return stateText + } parseNumberStart := -1 loop: diff --git a/batch/batch_test.go b/batch/batch_test.go index 51978283..fcafdd3b 100644 --- a/batch/batch_test.go +++ b/batch/batch_test.go @@ -67,6 +67,29 @@ select top 1 1`, select top 1 1`, }, }, + testItem{ + Sql: ` +create table t ( + id int, + gone_ts datetime +) +go +select + gone_ts +from test_table +go`, + Expect: []string{` +create table t ( + id int, + gone_ts datetime +) +`, ` +select + gone_ts +from test_table +`, + }, + }, testItem{Sql: `"0'"`, Expect: []string{`"0'"`}}, testItem{Sql: "0'", Expect: []string{"0'"}}, testItem{Sql: "--", Expect: []string{"--"}}, @@ -78,6 +101,7 @@ select top 1 1`, testItem{Sql: "select 'hi\\\r\n-hello';", Expect: []string{"select 'hi-hello';"}}, testItem{Sql: "select 'hi\\\r-hello';", Expect: []string{"select 'hi-hello';"}}, testItem{Sql: "select 'hi\\\n\nhello';", Expect: []string{"select 'hi\nhello';"}}, + testItem{Sql: "select\ngone_ts\nfrom t;", Expect: []string{"select\ngone_ts\nfrom t;"}}, } index := -1