Skip to content

Commit 5be11cb

Browse files
fix: MSSQLSERVER dual-entry bug, README batch script, and test DB dependency
- Remove duplicate (local) entry for default MSSQLSERVER instance - Fix README batch script: %%~z outside FOR loop doesn't work, use FOR %%I - TestHelpCommand/TestServerlistCommand no longer require DB connection
1 parent 1af7232 commit 5be11cb

4 files changed

Lines changed: 12 additions & 8 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ echo No SQL Server instances found
205205
To capture stderr separately (for error logging):
206206
```batch
207207
sqlcmd -Q ":serverlist" 2>errors.log > servers.txt
208-
if exist errors.log if not "%%~z errors.log"=="0" type errors.log
208+
if exist errors.log for %%I in (errors.log) do if %%~zI gtr 0 type errors.log
209209
```
210210

211211
```

pkg/sqlcmd/commands_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,9 +470,11 @@ func TestExitCommandAppendsParameterToCurrentBatch(t *testing.T) {
470470
}
471471

472472
func TestHelpCommand(t *testing.T) {
473-
s, buf := setupSqlCmdWithMemoryOutput(t)
474-
defer func() { _ = buf.Close() }()
473+
v := InitializeVariables(false)
474+
s := New(nil, "", v)
475+
buf := &memoryBuffer{buf: new(bytes.Buffer)}
475476
s.SetOutput(buf)
477+
defer func() { _ = buf.Close() }()
476478

477479
err := helpCommand(s, []string{""}, 1)
478480
assert.NoError(t, err, "helpCommand should not error")

pkg/sqlcmd/serverlist.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func GetLocalServerInstances() ([]string, error) {
8080
continue
8181
}
8282
if s == "MSSQLSERVER" {
83-
instances = append(instances, "(local)", serverName)
83+
instances = append(instances, serverName)
8484
} else {
8585
instances = append(instances, fmt.Sprintf(`%s\%s`, serverName, s))
8686
}

pkg/sqlcmd/serverlist_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,14 @@ func TestParseInstances(t *testing.T) {
7676
}
7777

7878
func TestServerlistCommand(t *testing.T) {
79-
s, buf := setupSqlCmdWithMemoryOutput(t)
79+
v := InitializeVariables(false)
80+
s := New(nil, "", v)
81+
buf := &memoryBuffer{buf: new(bytes.Buffer)}
82+
s.SetOutput(buf)
8083
defer func() { _ = buf.Close() }()
8184

82-
// Run the serverlist command
83-
c := []string{":serverlist"}
84-
err := runSqlCmd(t, s, c)
85+
// Run the serverlist command directly - no DB connection needed
86+
err := serverlistCommand(s, []string{""}, 1)
8587

8688
// The command should not raise an error even if no servers are found
8789
assert.NoError(t, err, ":serverlist should not raise error")

0 commit comments

Comments
 (0)