-
Notifications
You must be signed in to change notification settings - Fork 82
Add -f codepage flag for input/output encoding #638
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dlevy-msft-sql
wants to merge
18
commits into
microsoft:main
Choose a base branch
from
dlevy-msft-sql:round-out-part2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
170f439
feat: add -f codepage flag for input/output encoding
dlevy-msft-sql 5309eda
Merge branch 'main' into round-out-part2
dlevy-msft-sql 8a74e3b
Address Copilot review comments on codepage support
dlevy-msft-sql faa945c
Fix ineffectual assignment lint error
dlevy-msft-sql 424cc32
Address Copilot review comments for codepage support
dlevy-msft-sql 2a14b75
Fix locale-specific number formatting in codepage error
dlevy-msft-sql 06da044
refactor: consolidate codepage definitions into single registry
dlevy-msft-sql 065b1f4
test: add TestSupportedCodePages to verify registry consistency
dlevy-msft-sql 9b0cd91
Fix UTF-16 BOM handling and add Windows codepage fallback
dlevy-msft-sql ff05619
Address Copilot review comments for codepage implementation
dlevy-msft-sql 2e62e10
Address Copilot review comments (round 7)
dlevy-msft-sql b96e228
Fix codepage error message for locale-independent formatting
dlevy-msft-sql 4ddfd1a
Fix Windows codepage transformer to handle streaming correctly
dlevy-msft-sql 9c471b1
Address Copilot review: clarify BOM handling documentation
dlevy-msft-sql 4f14d0f
Merge branch 'main' into round-out-part2
dlevy-msft-sql a672f7f
Merge branch 'main' into round-out-part2
dlevy-msft-sql c05fae4
docs: add differences from ODBC sqlcmd section for codepage support
dlevy-msft-sql b284793
Merge branch 'main' into round-out-part2
dlevy-msft-sql File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -82,6 +82,11 @@ type SQLCmdArguments struct { | |
| ChangePassword string | ||
| ChangePasswordAndExit string | ||
| TraceFile string | ||
| CodePage string | ||
| // codePageSettings stores the parsed CodePageSettings after validation. | ||
| // This avoids parsing CodePage twice (in Validate and run). | ||
| codePageSettings *sqlcmd.CodePageSettings | ||
| ListCodePages bool | ||
| // Keep Help at the end of the list | ||
| Help bool | ||
| } | ||
|
|
@@ -171,6 +176,12 @@ func (a *SQLCmdArguments) Validate(c *cobra.Command) (err error) { | |
| err = rangeParameterError("-t", fmt.Sprint(a.QueryTimeout), 0, 65534, true) | ||
| case a.ServerCertificate != "" && !encryptConnectionAllowsTLS(a.EncryptConnection): | ||
| err = localizer.Errorf("The -J parameter requires encryption to be enabled (-N true, -N mandatory, or -N strict).") | ||
| case a.CodePage != "": | ||
| if codePageSettings, parseErr := sqlcmd.ParseCodePage(a.CodePage); parseErr != nil { | ||
| err = localizer.Errorf(`'-f %s': %v`, a.CodePage, parseErr) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } else { | ||
| a.codePageSettings = codePageSettings | ||
| } | ||
| } | ||
| } | ||
| if err != nil { | ||
|
|
@@ -239,6 +250,17 @@ func Execute(version string) { | |
| listLocalServers() | ||
| os.Exit(0) | ||
| } | ||
| // List supported codepages | ||
| if args.ListCodePages { | ||
| fmt.Println(localizer.Sprintf("Supported Code Pages:")) | ||
| fmt.Println() | ||
| fmt.Printf("%-8s %-20s %s\n", "Code", "Name", "Description") | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| fmt.Printf("%-8s %-20s %s\n", "----", "----", "-----------") | ||
| for _, cp := range sqlcmd.SupportedCodePages() { | ||
| fmt.Printf("%-8d %-20s %s\n", cp.CodePage, cp.Name, cp.Description) | ||
| } | ||
| os.Exit(0) | ||
| } | ||
| if len(argss) > 0 { | ||
| fmt.Printf("%s'%s': Unknown command. Enter '--help' for command help.", sqlcmdErrorPrefix, argss[0]) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| os.Exit(1) | ||
|
|
@@ -479,6 +501,8 @@ func setFlags(rootCmd *cobra.Command, args *SQLCmdArguments) { | |
| rootCmd.Flags().BoolVarP(&args.EnableColumnEncryption, "enable-column-encryption", "g", false, localizer.Sprintf("Enable column encryption")) | ||
| rootCmd.Flags().StringVarP(&args.ChangePassword, "change-password", "z", "", localizer.Sprintf("New password")) | ||
| rootCmd.Flags().StringVarP(&args.ChangePasswordAndExit, "change-password-exit", "Z", "", localizer.Sprintf("New password and exit")) | ||
| rootCmd.Flags().StringVarP(&args.CodePage, "code-page", "f", "", localizer.Sprintf("Specifies the code page for input/output. Use 65001 for UTF-8. Format: codepage | i:codepage[,o:codepage] | o:codepage[,i:codepage]")) | ||
| rootCmd.Flags().BoolVar(&args.ListCodePages, "list-codepages", false, localizer.Sprintf("List supported code pages and exit")) | ||
| } | ||
|
|
||
| func setScriptVariable(v string) string { | ||
|
|
@@ -817,6 +841,11 @@ func run(vars *sqlcmd.Variables, args *SQLCmdArguments) (int, error) { | |
| defer s.StopCloseHandler() | ||
| s.UnicodeOutputFile = args.UnicodeOutputFile | ||
|
|
||
| // Apply codepage settings (already parsed and validated in Validate) | ||
| if args.codePageSettings != nil { | ||
| s.CodePage = args.codePageSettings | ||
| } | ||
|
|
||
| if args.DisableCmd != nil { | ||
| s.Cmd.DisableSysCommands(args.errorOnBlockedCmd()) | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.