mssql-cli icon indicating copy to clipboard operation
mssql-cli copied to clipboard

Add a way to run commands from a file

Open chadwhitacre opened this issue 7 years ago • 20 comments
trafficstars

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 ':'.

screen shot 2018-01-11 at 9 54 55 am

$ 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 '\'.

chadwhitacre avatar Jan 11 '18 15:01 chadwhitacre

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.

pensivebrian avatar Jan 11 '18 19:01 pensivebrian

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

mikedavem avatar Feb 04 '18 09:02 mikedavem

+1 to this!

ohbadiah avatar May 08 '18 18:05 ohbadiah

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.

lycovian avatar May 16 '18 14:05 lycovian

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 mechanism. Thanks for creating a great tool for the community.

dooliecakes avatar Jan 09 '19 18:01 dooliecakes

@dooliecakes this feature is on our immediate timeline now. Will share updates as we proceed! Thanks all for the upvotes!

MrMeemus avatar Jan 10 '19 23:01 MrMeemus

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.

sudeepjana avatar Apr 08 '19 18:04 sudeepjana

+1 .. using mssql-cli in automation pipeline would be appreciated :)

mikedavem avatar Apr 08 '19 18:04 mikedavem

This would be incredibly helpful. Subscribed......

austin-priest avatar Apr 24 '19 22:04 austin-priest

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

bjhulst avatar Sep 16 '19 12:09 bjhulst

No timelines as of yet, but this is at the top of our list to implement once we have resources todo so.

pensivebrian avatar Sep 16 '19 17:09 pensivebrian

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 avatar Sep 18 '19 19:09 bjhulst

@bjhulst - a PR for this would be appreciated, but there wouldn't be any compensation for this.

pensivebrian avatar Sep 19 '19 17:09 pensivebrian

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

petergeneric avatar Dec 06 '19 10:12 petergeneric

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?

ellbosch avatar Dec 06 '19 18:12 ellbosch

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

dooliecakes avatar Dec 06 '19 18:12 dooliecakes

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?

Ah, I'm installing it via this yum repo: https://packages.microsoft.com/config/rhel/7/prod.repo

petergeneric avatar Dec 06 '19 21:12 petergeneric

Thanks @petergeneric. Looks like we haven't updated that release in a very long time. We'll have this updated in the near future.

ellbosch avatar Dec 06 '19 21:12 ellbosch

That'd be great, thanks!

petergeneric avatar Dec 06 '19 21:12 petergeneric

3.5 years later .. I just searched for this capability and .. here we are.

javadba avatar May 18 '23 12:05 javadba