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
Address Copilot review comments for codepage implementation
- Change UTF-16 BOM handling from IgnoreBOM to UseBOM for codepages
1200 (UTF-16 LE) and 1201 (UTF-16 BE) to properly strip BOMs on
decode (pkg/sqlcmd/codepage.go)
- Eliminate redundant CodePage parsing by storing parsed settings
in codePageSettings field after validation in Validate(), then
reusing in run() (cmd/sqlcmd/sqlcmd.go)
- Add comprehensive Code Page Support documentation section to
README.md with format guide, common codepages table, practical
examples, and notes on default behavior
Note: Integration test for IncludeFile with non-UTF8 input already
exists in TestIncludeFileWithInputCodePage (pkg/sqlcmd/sqlcmd_test.go)
Copy file name to clipboardExpand all lines: README.md
+63-1Lines changed: 63 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -133,7 +133,7 @@ The following switches have different behavior in this version of `sqlcmd` compa
133
133
- To provide the value of the host name in the server certificate when using strict encryption, pass the host name with `-F`. Example: `-Ns -F myhost.domain.com`
134
134
- 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
135
-`-u` The generated Unicode output file will have the UTF16 Little-Endian Byte-order mark (BOM) written to it.
136
-
-`-f` Specifies the code page for input and output files. Format: `codepage | i:codepage[,o:codepage] | o:codepage[,i:codepage]`. Use `65001` for UTF-8. Supported codepages include Unicode (65001, 1200, 1201), Windows (874, 1250-1258), OEM/DOS (437, 850, etc.), ISO-8859 (28591-28606), CJK (932, 936, 949, 950), and EBCDIC (37, 1047, 1140). On Windows, additional codepages installed on the system (such as Japanese EBCDIC) are also available. Use `--list-codepages` to see all supported code pages.
136
+
-`-f` Specifies the code page for input and output files. See [Code Page Support](#code-page-support) below for details and examples.
137
137
- Some behaviors that were kept to maintain compatibility with `OSQL` may be changed, such as alignment of column headers for some data types.
138
138
- 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.
139
139
-`-i` doesn't handle a comma `,` in a file name correctly unless the file name argument is triple quoted. For example:
@@ -238,6 +238,68 @@ To see a list of available styles along with colored syntax samples, use this co
238
238
:list color
239
239
```
240
240
241
+
### Code Page Support
242
+
243
+
The `-f` flag specifies the code page for reading input files and writing output. This is useful when working with SQL scripts saved in legacy encodings or when output needs to be in a specific encoding.
244
+
245
+
#### Format
246
+
247
+
```
248
+
-f codepage # Set both input and output to the same codepage
249
+
-f i:codepage # Set input codepage only
250
+
-f o:codepage # Set output codepage only
251
+
-f i:codepage,o:codepage # Set input and output to different codepages
252
+
-f o:codepage,i:codepage # Same as above (order doesn't matter)
253
+
```
254
+
255
+
#### Common Code Pages
256
+
257
+
| Code Page | Name | Description |
258
+
|-----------|------|-------------|
259
+
| 65001 | UTF-8 | Unicode (UTF-8) - default for most modern systems |
0 commit comments