You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In interactive mode, EXIT(query) can now span multiple lines when parentheses
are unbalanced. Handles SQL strings, comments, and bracket identifiers correctly.
Includes protection against infinite loops (max 1000 continuation lines) and
user-friendly error messages for EOF/incomplete commands.
Copy file name to clipboardExpand all lines: README.md
+18-1Lines changed: 18 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -112,6 +112,24 @@ sqlcmd
112
112
113
113
If no current context exists, `sqlcmd` (with no connection parameters) reverts to the original ODBC `sqlcmd` behavior of creating an interactive session to the default local instance on port 1433 using trusted authentication, otherwise it will create an interactive session to the current context.
114
114
115
+
### Interactive Mode Commands
116
+
117
+
In interactive mode, `sqlcmd` supports several special commands. The `EXIT` command can execute a query and use its result as the exit code:
118
+
119
+
```
120
+
1> EXIT(SELECT 100)
121
+
```
122
+
123
+
For complex queries, `EXIT(query)` can span multiple lines. When parentheses are unbalanced, `sqlcmd` prompts for continuation:
124
+
125
+
```
126
+
1> EXIT(SELECT 1
127
+
-> + 2
128
+
-> + 3)
129
+
```
130
+
131
+
The query result (6 in this example) becomes the process exit code.
132
+
115
133
## Sqlcmd
116
134
117
135
The `sqlcmd` project aims to be a complete port of the original ODBC sqlcmd to the `Go` language, utilizing the [go-mssqldb][] driver. For full documentation of the tool and installation instructions, see [go-sqlcmd-utility][].
@@ -134,7 +152,6 @@ The following switches have different behavior in this version of `sqlcmd` compa
134
152
- More information about client/server encryption negotiation can be found at <https://docs.microsoft.com/openspecs/windows_protocols/ms-tds/60f56408-0188-4cd5-8b90-25c6f2423868>
135
153
-`-u` The generated Unicode output file will have the UTF16 Little-Endian Byte-order mark (BOM) written to it.
136
154
- Some behaviors that were kept to maintain compatibility with `OSQL` may be changed, such as alignment of column headers for some data types.
137
-
- All commands must fit on one line, even `EXIT`. Interactive mode will not check for open parentheses or quotes for commands and prompt for successive lines. The ODBC sqlcmd allows the query run by `EXIT(query)` to span multiple lines.
138
155
-`-i` doesn't handle a comma `,` in a file name correctly unless the file name argument is triple quoted. For example:
139
156
`sqlcmd -i """select,100.sql"""` will try to open a file named `sql,100.sql` while `sqlcmd -i "select,100.sql"` will try to open two files `select` and `100.sql`
140
157
- If using a single `-i` flag to pass multiple file names, there must be a space after the `-i`. Example: `-i file1.sql file2.sql`
0 commit comments