mssql-cli
mssql-cli copied to clipboard
Add a way to run commands from a file
sqlcmd provides a :r meta-command to run commands from a file in the current session. psql spells it \i. Does this feature exist in mssql-cli? I tried both :r and (for the heck of it) \i to no avail, though the latter did pop up a tantalizing file browser. 🤔
$ mssql-cli -d foo
Version: 0.8.0
Mail: [email protected]
Home: http://github.com/dbcli/mssql-cli
foo>:r bar.sql
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near ':'.

$ mssql-cli -d foo
Version: 0.8.0
Mail: [email protected]
Home: http://github.com/dbcli/mssql-cli
foo>\i foo.sql
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '\'.
Hello, @whit537. Currently, mssql-cli does not support running command from a file. However, adding support for this is on our roadmap, though I don't have any exact timelines. If I had to guess, this is two, maybe three months out. Thanks for the feedback! Issues like this, along with upvotes, help prioritize our work.
In addition to the chadwhitacre request, would be possible to add execute commands from a file with "pause" capability. I may see an particular interest during demonstrations where we want to display step by step results. Something as
mssql-cli -f file.sql
file.sql content:
` select name from sys.databases where database_id = 2 --> display result pause
use tempdb; select * from sys.database_files --> Display result pause `
Regards
+1 to this!
I was curious as to the status of being able to pipe or run script files. Also +1 as it would solve a important developer CI/CD use case for us.
Is there an update on this request? I would love to be able to script queries via something like --query "select bla from bla" or a --file
@dooliecakes this feature is on our immediate timeline now. Will share updates as we proceed! Thanks all for the upvotes!
Is there any further updates on this? I'd love to be able to run queries from a file as well, so we can integrate this tool into our automation pipeline.
+1 .. using mssql-cli in automation pipeline would be appreciated :)
This would be incredibly helpful. Subscribed......
Any update on the timeline for this feature?
I am now using this workaround:
mssql-cli -S servername -U username -P password << EOF use "some_place"; select * from table; EOF
No timelines as of yet, but this is at the top of our list to implement once we have resources todo so.
Brian I could free up some time and prepare a PR... just wondering since this is open source backed by Microsoft and needs an IPR related agrreement before submitting code ... will this be like subcontracting for Microsoft and possibly compensated in any way? Just wondering....
@bjhulst - a PR for this would be appreciated, but there wouldn't be any compensation for this.
It looks like documentation has been added for non-interactive options - the -Q and -i arguments, however the installable version lacks these features (also: there has been no release since July 2018!) Could you do a release with this functionality? It's documented at https://github.com/dbcli/mssql-cli/blob/master/doc/usage_guide.md#non-interactive-options
Hi @petergeneric, I've only been publishing official builds to pip so far. You can get the latest installation via Python by calling pip install mssql-cli.
Where are you currently trying to install from, out of curiosity?
Guys, I just upgraded and tried it out - works like a charm! Thankyou so much for adding this, it’s a game changer for me.
Shaun
On Fri, Dec 6, 2019 at 10:17 AM Elliot Boschwitz [email protected] wrote:
Hi @petergeneric https://github.com/petergeneric, I've only been publishing official builds to pip so far. You can get the latest installation via Python by calling pip install mssql-cli.
Where are you currently trying to install from, out of curiosity?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/dbcli/mssql-cli/issues/139?email_source=notifications&email_token=AJ66OANNDJO2BXZ7E64BG6DQXKJMBA5CNFSM4ELL42VKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEGE5S3Y#issuecomment-562682223, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJ66OAK35EJJMGZA2RY2PR3QXKJMBANCNFSM4ELL42VA .
-- null
Hi @petergeneric, I've only been publishing official builds to
pipso far. You can get the latest installation via Python by callingpip install mssql-cli.Where are you currently trying to install from, out of curiosity?
Ah, I'm installing it via this yum repo: https://packages.microsoft.com/config/rhel/7/prod.repo
Thanks @petergeneric. Looks like we haven't updated that release in a very long time. We'll have this updated in the near future.
That'd be great, thanks!
3.5 years later .. I just searched for this capability and .. here we are.