-
Notifications
You must be signed in to change notification settings - Fork 79
Allow -q (initial query) to work with -i (input files) #626
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
base: main
Are you sure you want to change the base?
Allow -q (initial query) to work with -i (input files) #626
Conversation
Previously -q and -i were mutually exclusive. Now the initial query (-q) runs first, then the input files (-i) are processed. This is useful for setting session options before running scripts. Example: sqlcmd -S server -q 'SET PARSEONLY ON' -i script.sql The -Q flag (query and exit) remains mutually exclusive with -i since -Q causes sqlcmd to exit immediately after the query. Fixes microsoft#389
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR enables the -q (initial query) flag to work alongside -i (input files), allowing users to set session options before running scripts. Previously, -q was mutually exclusive with -i, but now the initial query runs first, followed by the input files. The -Q (query and exit) flag remains mutually exclusive with -i as expected.
Changes:
- Modified validation to allow
-iwith-qwhile keeping-iand-Qmutually exclusive - Updated run logic to execute
-qbefore processing-ifiles - Updated flag descriptions and documentation
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| cmd/sqlcmd/sqlcmd.go | Modified validation logic to distinguish between -q and -Q, updated run logic to execute initial query before input files, and updated flag description |
| cmd/sqlcmd/sqlcmd_test.go | Updated test expectations to reflect that only -Q (not -q) is mutually exclusive with -i, added test for -q with -i combination |
| README.md | Added documentation for the new feature with example usage |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Fix typo: '-i' instead of 'i' in mutuallyExclusiveError call - Add InitialQuery check to prevent double s.Run() when using -q alone
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.
Summary
This PR allows the
-q(initial query) flag to be used with-i(input files), enabling users to set session options before running scripts.Changes
-iwith-Q(not-q)-qfirst, then process-ifiles-iflag description to document the new behaviorUsage
The initial query runs first, then the input files are processed.
Notes
-Qflag (query and exit) remains mutually exclusive with-isince-Qcauses sqlcmd to exit immediately after the queryFixes #389