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
7 changes: 4 additions & 3 deletions pkg/sqlcmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ func newCommands() Commands {
isSystem: true,
},
"ONERROR": {
regex: regexp.MustCompile(`(?im)^[\t ]*?:?ONERROR(?:[ \t]+(.*$)|$)`),
action: onerrorCommand,
name: "ONERROR",
regex: regexp.MustCompile(`(?im)^[\t ]*?:?ONERROR(?:[ \t]+(.*$)|$)`),
action: onerrorCommand,
name: "ONERROR",
},
}
}
Expand Down Expand Up @@ -474,6 +474,7 @@ func onerrorCommand(s *Sqlcmd, args []string, line uint) error {
s.Connect.ExitOnError = true
} else if strings.EqualFold(strings.ToLower(params), "ignore") {
s.Connect.IgnoreError = true
s.Connect.ExitOnError = false
} else {
return InvalidCommandError("ON ERROR", line)
}
Expand Down
10 changes: 10 additions & 0 deletions pkg/sqlcmd/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,16 @@ func TestOnErrorCommand(t *testing.T) {
err = runSqlCmd(t, s, []string{":ONERROR exit", "printtgit N'message'", "SELECT @@versionn", "GO"})
assert.NoError(t, err, "runSqlCmd")
assert.Equal(t, 1, s.Exitcode, "ExitCode")
// -b sets ExitOnError true
s.Connect.ExitOnError = true
err = runSqlCmd(t, s, []string{":ONERROR ignore", "printtgit N'message'", "SELECT @@versionn", "GO"})
// when ignore is set along with -b command , ignore takes precedence and resets ExitOnError
assert.Equal(t, false, s.Connect.ExitOnError, "ExitOnError")
assert.NoError(t, err, "runSqlCmd")
// checking ExitonError with Exit option
err = runSqlCmd(t, s, []string{":ONERROR exit", "printtgit N'message'", "SELECT @@versionn", "GO"})
assert.Equal(t, true, s.Connect.ExitOnError, "ExitOnError")
assert.NoError(t, err, "runSqlCmd")
}
func TestResolveArgumentVariables(t *testing.T) {
type argTest struct {
Expand Down