microsoft / microsoft/go-sqlcmd
Make -q and -i work together
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 595
- Forks
- 91
- Avg merge
- 9h 35m
- Merged PRs (30d)
- 1
Description
Discussed in https://github.com/microsoft/go-sqlcmd/discussions/206
Originally posted by 0x7FFFFFFFFFFFFFFF February 2, 2023
Right now, both sqlcmd and go-sqlcmd don't allow you to specify -q and -i options together. Below is the output of both commands.
c:\temp>sqlcmd -S . -E -q "SET PARSEONLY ON" -i test.sql
Sqlcmd: The i and the -Q/-q options are mutually exclusive.
c:\temp>sqlcmdgo -S . -E -q "SET PARSEONLY ON" -i test.sql
sqlcmdgo: error: --input-file and --initial-query can't be used together
c:\temp>
If this is possible, it will be very useful. In my case, I have a huge file test.sql that is not practical to open in SSMS. What I want is to check its syntax, just like what we normally do by clicking the Parse toolbar button in SSMS. What SSMS actually does is run the command SET PARSEONLY ON before your actually SQL code. If go-sqlcmd can allow us to execute a custom command and then an SQL file, it will basically allow us to parse huge SQL files without having to prepend the literal text SET PARSEONLY ON at the beginng of the file. This feature might be useful in some other cases, too. Hope you can consider adding this. Thanks.
Note there are 2 ways to accomplish the same result today, but they both require saving your boilerplate script to a file.
- Use multiple
-ivalues and include your custom command file first - Set the environment variable
SQLCMDINIto the path of your custom command file and sqlcmd will run that script upon launch.
Enabling -q to work alongside -i would provide a more flexible solution.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the go-sqlcmd CLI handling for the -q/--initial-query and -i/--input-file options, then compare it with the documented multiple -i behavior. The change is done when a custom initial query can run before the SQL file without the options being rejected; add or update coverage for their combined use.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, sql
- Domain
- cli, databases
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100