From 11f241bb381482a0077b887633ad29876c551f88 Mon Sep 17 00:00:00 2001 From: davidshi Date: Wed, 27 Sep 2023 11:01:27 -0500 Subject: [PATCH 1/3] allow tabs in commands --- pkg/sqlcmd/commands_test.go | 3 ++- pkg/sqlcmd/parse.go | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/sqlcmd/commands_test.go b/pkg/sqlcmd/commands_test.go index 1119df93..94caeb2e 100644 --- a/pkg/sqlcmd/commands_test.go +++ b/pkg/sqlcmd/commands_test.go @@ -43,10 +43,11 @@ func TestCommandParsing(t *testing.T) { {`:Setvar A1 "some value" `, "SETVAR", []string{`A1 "some value" `}}, {` :Listvar`, "LISTVAR", []string{""}}, {`:EXIT (select 100 as count)`, "EXIT", []string{" (select 100 as count)"}}, + {"\t:EXIT (select 100 as count)", "EXIT", []string{" (select 100 as count)"}}, {`:EXIT ( )`, "EXIT", []string{" ( )"}}, {`EXIT `, "EXIT", []string{" "}}, {`:Connect someserver -U someuser`, "CONNECT", []string{"someserver -U someuser"}}, - {`:r c:\$(var)\file.sql`, "READFILE", []string{`c:\$(var)\file.sql`}}, + {":r\tc:\\$(var)\\file.sql", "READFILE", []string{`c:\$(var)\file.sql`}}, {`:!! notepad`, "EXEC", []string{" notepad"}}, {`:!!notepad`, "EXEC", []string{"notepad"}}, {` !! dir c:\`, "EXEC", []string{` dir c:\`}}, diff --git a/pkg/sqlcmd/parse.go b/pkg/sqlcmd/parse.go index c1c10ef4..11dd14e1 100644 --- a/pkg/sqlcmd/parse.go +++ b/pkg/sqlcmd/parse.go @@ -34,7 +34,7 @@ func readMultilineComment(r []rune, i, end int) (int, bool) { func readCommand(c Commands, r []rune, i, end int) (*Command, []string, int) { for ; i < end; i++ { next := grab(r, i, end) - if next == 0 || unicode.IsControl(next) { + if next == 0 || (unicode.IsControl(next) && next != '\t') { break } } From d67140d5ed77bc78272fcefb42ef5ebf699066cd Mon Sep 17 00:00:00 2001 From: davidshi Date: Fri, 29 Sep 2023 14:06:38 -0500 Subject: [PATCH 2/3] Fix variable substitution --- pkg/sqlcmd/sqlcmd.go | 8 +++++--- pkg/sqlcmd/sqlcmd_test.go | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/pkg/sqlcmd/sqlcmd.go b/pkg/sqlcmd/sqlcmd.go index a4e37c07..3293253b 100644 --- a/pkg/sqlcmd/sqlcmd.go +++ b/pkg/sqlcmd/sqlcmd.go @@ -389,6 +389,8 @@ func (s *Sqlcmd) getRunnableQuery(q string) string { } b := new(strings.Builder) b.Grow(len(q)) + // The varmap index is rune based not byte based + r := []rune(q) keys := make([]int, 0, len(s.batch.varmap)) for k := range s.batch.varmap { keys = append(keys, k) @@ -396,7 +398,7 @@ func (s *Sqlcmd) getRunnableQuery(q string) string { sort.Ints(keys) last := 0 for _, i := range keys { - b.WriteString(q[last:i]) + b.WriteString(string(r[last:i])) v := s.batch.varmap[i] if val, ok := s.resolveVariable(v); ok { b.WriteString(val) @@ -404,9 +406,9 @@ func (s *Sqlcmd) getRunnableQuery(q string) string { _, _ = fmt.Fprintf(s.GetError(), "'%s' scripting variable not defined.%s", v, SqlcmdEol) b.WriteString(fmt.Sprintf("$(%s)", v)) } - last = i + len(v) + 3 + last = i + len([]rune(v)) + 3 } - b.WriteString(q[last:]) + b.WriteString(string(r[last:])) return b.String() } diff --git a/pkg/sqlcmd/sqlcmd_test.go b/pkg/sqlcmd/sqlcmd_test.go index fbc5c915..3e4729b5 100644 --- a/pkg/sqlcmd/sqlcmd_test.go +++ b/pkg/sqlcmd/sqlcmd_test.go @@ -246,6 +246,7 @@ func TestGetRunnableQuery(t *testing.T) { {"$ (var2)", "$ (var2)"}, {"select '$(VAR1) $(VAR2)' as c", "select 'v1 variable2' as c"}, {" $(VAR1) ' $(VAR2) ' as $(VAR1)", " v1 ' variable2 ' as v1"}, + {"í $(VAR1)", "í v1"}, } s := New(nil, "", v) for _, test := range tests { From b7fa6f52d3f2ed1ac0aae95279bd94098c19aa36 Mon Sep 17 00:00:00 2001 From: davidshi Date: Tue, 24 Oct 2023 09:39:06 -0500 Subject: [PATCH 3/3] fix notice --- NOTICE.md | 55 ++++++++++++------------------------------------------- 1 file changed, 12 insertions(+), 43 deletions(-) diff --git a/NOTICE.md b/NOTICE.md index db40b7f5..96e5b720 100644 --- a/NOTICE.md +++ b/NOTICE.md @@ -587,8 +587,8 @@ Apache License ## github.com/docker/docker * Name: github.com/docker/docker -* Version: v20.10.24 -* License: [Apache-2.0](https://github.com/docker/docker/blob/v20.10.24/LICENSE) +* Version: v24.0.6 +* License: [Apache-2.0](https://github.com/docker/docker/blob/v24.0.6/LICENSE) ``` @@ -4182,37 +4182,6 @@ SUBDIRECTORIES ``` -## github.com/sirupsen/logrus - -* Name: github.com/sirupsen/logrus -* Version: v1.9.0 -* License: [MIT](https://github.com/sirupsen/logrus/blob/v1.9.0/LICENSE) - -``` -The MIT License (MIT) - -Copyright (c) 2014 Simon Eskildsen - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. - -``` - ## github.com/spf13/afero * Name: github.com/spf13/afero @@ -4743,8 +4712,8 @@ THE SOFTWARE. ## golang.org/x/crypto * Name: golang.org/x/crypto -* Version: v0.12.0 -* License: [BSD-3-Clause](https://cs.opensource.google/go/x/crypto/+/v0.12.0:LICENSE) +* Version: v0.14.0 +* License: [BSD-3-Clause](https://cs.opensource.google/go/x/crypto/+/v0.14.0:LICENSE) ``` Copyright (c) 2009 The Go Authors. All rights reserved. @@ -4780,8 +4749,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## golang.org/x/net * Name: golang.org/x/net -* Version: v0.14.0 -* License: [BSD-3-Clause](https://cs.opensource.google/go/x/net/+/v0.14.0:LICENSE) +* Version: v0.17.0 +* License: [BSD-3-Clause](https://cs.opensource.google/go/x/net/+/v0.17.0:LICENSE) ``` Copyright (c) 2009 The Go Authors. All rights reserved. @@ -4814,11 +4783,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ``` -## golang.org/x/sys +## golang.org/x/sys/windows -* Name: golang.org/x/sys -* Version: v0.11.0 -* License: [BSD-3-Clause](https://cs.opensource.google/go/x/sys/+/v0.11.0:LICENSE) +* Name: golang.org/x/sys/windows +* Version: v0.13.0 +* License: [BSD-3-Clause](https://cs.opensource.google/go/x/sys/+/v0.13.0:LICENSE) ``` Copyright (c) 2009 The Go Authors. All rights reserved. @@ -4854,8 +4823,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## golang.org/x/text * Name: golang.org/x/text -* Version: v0.12.0 -* License: [BSD-3-Clause](https://cs.opensource.google/go/x/text/+/v0.12.0:LICENSE) +* Version: v0.13.0 +* License: [BSD-3-Clause](https://cs.opensource.google/go/x/text/+/v0.13.0:LICENSE) ``` Copyright (c) 2009 The Go Authors. All rights reserved.