RSQL Client (rcli)

The RSQL Client rcli is a utility program that allows you to send SQL script files to the server.

The result received from the server is printed to the terminal.

Syntax

rcli [OPTIONS] [FILE...]

rcli [OPTIONS] -Q="query_string"

Arguments

OPTIONS
available options can be printed with rcli -h.
FILE…
one or more SQL script files, which will be sent to the server.
query_string
a script text, which will be sent to the server.

Configuration File

To avoid specifying the login, password and other options each time you connect to a server, it is more convenient to specify them in a config file.

By default, the config file used by rcli program is rcli.conf. If it doesn’t exist in the current directory, it is looked up in the user’s home directory.

A model config file can be created with the following command:

rcli -config_model > ~/rcli.conf
chmod 600 ~/rcli.conf

A new config file has been created in your home directory. Only you have the permission to open and modify it. In particular, you will change the login_name and password parameters.

This is an example of a typical rcli.conf file for Linux (for Windows, the content is slightly different):

# usually, the name of this file is rcli.conf, located in the user's home directory

# this is the configuration file of the command line rsql client, "rcli", in TOML format.
# for TOML, see https://github.com/toml-lang/toml

[remote_server]
    address            = "localhost:7777"     # ip and port


[login]
    login_name         = "sa"                 # login name
    password           = "changeme"           # to ensure that nobody can see your password, set the access mode of this configuration file to 400 or 600, e.g.    chmod 600 rcli.conf
    # default_database   = "trashdb"            # force the default database for connection. Else, the default database for the login is used.


[presentation]
    file_encoding      = "utf-8"              # encoding of input file
    null_string        = "␀"                  # string displayed by SELECT for NULL values. "␀" is the unicode symbol for Null, which I think is a better choice than the string "Null". You can also use some unusual symbol, like "¬", if you like it better.
    width_limit        = 30                   # column width for displaying VARBINARY and VARCHAR
    fractional_second  = 3                    # number of fractional second digits, for displaying TIME and DATETIME
    print_mode         = 0                    # PRINT mode for multiple values. 0: normal mode, 1: column aligned
    error_level        = 0                    # level of details displayed when error is printed. 0, 1, 2
    error_wrap         = true                 # if true, error message is printed on a new line
    color              = true                 # if true, error message is printed in color

[internal]
    keepalive_interval = 20                   # keepalive messages are sent to the server at this rate, in seconds. By default, 20 seconds.

You can create many config files with different names, and choose between them with the -config option:

rcli -config=myconfig1.conf myscript.sql

If you want to know which config file has been read, use the -v option:

rcli -config=myconfig1.conf -v myscript.sql

If the argument of -config option is a relative path and the config file is not found at this location, it will be looked up relative to the user’s home directory.

Script File

A script file contains one or many batches.

A batch is a list of TSQL statements, sent as a whole to the server for execution.

Batches are separated with GO or EXIT commands.

If a script file contains many batches, they are sent to the server one after another.

Examples

This command prints available options:

rcli -h

Connect to the server and send a SQL script string:

rcli -U=sa -P=mypassword -S=localhost:7777 -d=mydatabase -Q="print 'Hello';"

Connect to the server and send a SQL script file:

rcli -U=sa -P=mypassword -S=localhost:7777 -d=mydatabase myscript.sql

Connect to the server and send a SQL script file.
Width is 40 characters for varchar columns, and nanoseconds are printed for time and datetime columns:

rcli -U=sa -P=mypassword -S=localhost:7777 -d=mydatabase -width=40 -fracsec=9 myscript.sql

Connect to the server with the login and password stored in ~/rcli.conf config file:

rcli myscript.sql