dbcli / mssql-cli

A command-line client for SQL Server with auto-completion and syntax highlighting
BSD 3-Clause "New" or "Revised" License
1.35k stars 191 forks source link

Documentation says can use -Q or -i, but not seeing in version 0.16.0 on Linux #410

Closed jrglynn2 closed 4 years ago

jrglynn2 commented 4 years ago

Documentation here ( https://github.com/dbcli/mssql-cli/blob/master/doc/usage_guide.md) references the following:

Non-Interactive Options
Non-interactive mode is a great way to query SQL Server using mssql-cli without needing to jump into an interactive command-line interface.

Executing a Query in Non-Interactive Mode
mssql-cli supports the following options for query exection in non-interactive mode:

Note: Ensure a connection to your server is established using the -S, -U, -P, and -d arguments, or by specifying your environment variables.

-Q, --query
To make a query in non-interactive mode, use the -Q (or --query) argument, followed by a T-SQL statement surrounded in double or single quotes. sqlcmd syntax is also supported.

-i, --input-file
An input file using T-SQL or sqlcmd syntax may be specified as an alternative to using -Q.

I do not see this in version 0.16.0, in Linux, and it is not listed in the --help:

mssql-cli --help
usage: mssql-cli [-h] [-U] [-P] [-d] [-S] [-E] [-v] [--mssqlclirc]
                 [--row-limit] [--less-chatty] [--auto-vertical-output] [-N]
                 [-C] [-l] [-K] [-M] [-a] [-A]
                 [--enable-sqltoolsservice-logging] [--prompt]

Microsoft SQL Server CLI. Version 0.16.0

optional arguments:
  -h, --help            show this help message and exit
  -U , --username       Username to connect to the database
  -P , --password       If not supplied, defaults to value in environment
                        variable MSSQL_CLI_PASSWORD.
  -d , --database       database name to connect to.
  -S , --server         SQL Server instance name or address.
  -E, --integrated      Use integrated authentication on windows.
  -v, --version         Version of mssql-cli.
  --mssqlclirc          Location of mssqlclirc config file.
  --row-limit           Set threshold for row limit prompt. Use 0 to disable
                        prompt.
  --less-chatty         Skip intro on startup and goodbye on exit.
  --auto-vertical-output
                        Automatically switch to vertical output mode if the
                        result is wider than the terminal width.
  -N, --encrypt         SQL Server uses SSL encryption for all data if the
                        server has a certificate installed.
  -C, --trust-server-certificate
                        The channel will be encrypted while bypassing walking
                        the certificate chain to validate trust.
  -l , --connect-timeout
                        Time in seconds to wait for a connection to the server
                        before terminating request.
  -K , --application-intent
                        Declares the application workload type when connecting
                        to a database in a SQL Server Availability Group.
  -M, --multi-subnet-failover
                        If application is connecting to AlwaysOn AG on
                        different subnets, setting this provides faster
                        detection and connection to currently active server.
  -a , --packet-size    Size in bytes of the network packets used to
                        communicate with SQL Server.
  -A, --dac-connection  Connect to SQL Server using the dedicated
                        administrator connection.
  --enable-sqltoolsservice-logging
                        Enables diagnostic logging for the SqlToolsService.
  --prompt              Prompt format (Default: \d>

How do I utilize the Non-Interactive Options in Linux, or if it is not available yet, is there an ETA?

Thanks!

--J

jrglynn2 commented 4 years ago

I found that I can use cat <FILENAME> | mssql-cli ... or echo '<SINGLE QUERY>' | mssql-cli ... and that works.

Is that the expected usage in Linux, or is there a way / plan to use the -Q and -i options?

Thanks,

--J

ellbosch commented 4 years ago

0.16 is out of date—I'm currently working on updating mssql-cli for apt-get and yum.

In the meantime, you may install mssql-cli using pip by calling pip install mssql-cli, after installing Python. This will provide you the latest version of mssql-cli which contains -Q and -i.