1=head1 NAME
2
3sqsh - Interactive database shell (version 2.5)
4
5=head1 SYNOPSIS
6
7       sqsh [[options]] [[args......]]
8            [ -a count ]
9            [ -A packet_size ]
10            [ -b ]
11            [ -B ]
12            [ -c [cmdend] ]
13            [ -C sql ]
14            [ -d severity ]
15            [ -D database ]
16            [ -e ]
17            [ -E editor ]
18            [ -f severity ]
19            [ -G tds_version ]
20            [ -h ]
21            [ -H hostname ]
22            [ -i filename ]
23            [ -I interfaces ]
24            [ -J charset ]
25            [ -k keywords ]
26            [ -K keytab]
27            [ -l debug_flags ]
28            [ -L var=value ]
29            [ -m style ]
30            [ -n on|off ]
31            [ -N appname ]
32            [ -o filename ]
33            [ -p ]
34            [ -P [password] ]
35            [ -Q query_timeout ]
36            [ -r [sqshrc] ]
37            [ -R server principal ]
38            [ -s colsep ]
39            [ -S server ]
40            [ -t [filter] ]
41            [ -T login_timeout ]
42            [ -U username ]
43            [ -v ]
44            [ -V [bcdimoqru]]
45            [ -w width ]
46            [ -X ]
47            [ -y directory ]
48            [ -z language ]
49            [ -Z [secmech|default|none] ]
50
51=head1 DESCRIPTION
52
53Sqsh (pronounced skwish) is short for SQshelL (pronounced s-q-shell), and is
54intended as a replacement for the venerable 'isql' program supplied by
55Sybase. It came about due to years of frustration of trying to do real work with
56a program that was never meant to perform real work.
57
58Sqsh is much more than a nice prompt, it is intended to provide much of the
59functionality provided by a good shell, such as variables, aliasing,
60redirection, pipes, back-grounding, job control, history, command substitution,
61and dynamic configuration. Also, as a by-product of the design, it is remarkably
62easy to extend and add functionality.
63
64=head1 OPTIONS
65
66The following options may be used to adjust some of the behavior of sqsh,
67however a large portion of the configuration options are available only through
68environment variables which may be set at runtime or via a .sqshrc file.
69
70Options may also be supplied in the SQSH environment variable. This variable is
71parsed prior to parsing the command line, so in most cases the command line will
72override the contents of the variable. Be aware that for options which are
73allowed to be supplied multiple times, such as B<-c>, supplying them both in a
74variable and on the command line will be the same as supplying them multiple
75times on the command line.
76
77=over 4
78
79=item -a count
80
81Sets the maximum I<count> of failures (as determined by the B<$thresh_fail>
82variable) that may occur before sqsh will abort. Setting this to 0 indicates
83that sqsh should not exit on errors. This value defaults to 0 and may also be
84set using the B<$thresh_exit> variable. See section B<EXIT STATUS> for details.
85
86=item -A packetsize
87
88Specifies the size of the network TDS packets used to communicate with the SQL
89server. This value must be between 512 and 8192, and be a multiple of 512. Check
90your SQL Server configuration to determine supported packet sizes. This value
91may also be specified at run-time using the B<$packet_size> variable.
92
93=item -b
94
95Suppress the banner message upon startup. This is unnecessary in cases where
96stdout has been redirected to a file. This option may also be set via the
97B<$banner> variable.
98
99=item -B
100
101Turns off all buffering of stdin, stdout, and stderr. This feature allows sqsh
102to be run from an interactive control script such as chat and expect.
103
104=item -c [cmdend]
105
106Internally sqsh provides the command B<\go> to send a batch of SQL to the
107database and provides a single alias, B<go> for this command. Each time
108I<cmdend> is supplied a new alias for B<\go> is established.
109
110=item -C sql
111
112Causes the I<sql> command to be executed by sqsh, similar to the same behavior
113exhibited by the -i flag. This I<sql> statement may not contain double quotes
114(this limitation may be lifted in a future release of sqsh).
115
116=item -d severity
117
118Sets the minimum SQL Server error severity that will be displayed to the user.
119The default is 0, and valid ranges are from 0 to 22. This may also be set using
120the B<$thresh_display> variable. See section B<EXIT STATUS>.
121
122=item -D database
123
124Causes sqsh to attempt to start with your database context set to I<database>
125rather than your default database (usually master). This may also be set using
126the B<$database> variable.
127
128=item -e
129
130Includes each command issued to sqsh to be included in the output. This option
131may also be set via the B<$echo> variable (which is unrelated to the B<\echo>
132command).
133
134=item -E editor
135
136Set the default editor to I<editor>. This may also be set using the UNIX
137environment variable B<$EDITOR> to the name of the editor desired.
138
139=item -f severity
140
141Sets the minimum I<severity> level considered a failure by sqsh. This is the
142same as setting the B<$thresh_fail> variable. See section B<EXIT STATUS> for
143details.
144
145=item -G tds_version
146
147Set the TDS version to use. Valid versions are 4.0, 4.2, 4.6, 4.9.5, 5.0 and
148freetds additionally supports versions 7.0 and 8.0. The specified value is
149assigned to the variable B<$tds_version>. Input validation is not performed by
150sqsh. However, when an invalid TDS version is specified, the default version of
1515.0 will be used. After a session is setup, the variable B<$tds_version> will be
152set to the TDS version in effect. The variable will not be available if option
153-G is not used. Meant for test and debugging purposes only.
154
155TDS stands for Tabular Data Stream and is the communication protocol Sybase and
156Microsoft uses for Client-Server communication.
157
158=item -h
159
160Turns off column headers and trailing "(# rows affected)" from batch output.
161
162=item -H hostname
163
164Sets the client hostname as reported in sysprocesses. This may also be set via
165the B<$hostname> variable.
166
167=item -i filename
168
169Read all input from I<filename> rather than from stdin.
170
171=item -I interfaces
172
173When a connection is established to the database, the I<interfaces> file is used
174to turn the value of B<$DSQUERY> into the hostname and port to which the
175connection will be made, by default this is located in B<$SYBASE>/interfaces.
176This flag allows this default to be overridden.
177
178=item -J charset
179
180Specifies the character set to be used on the client side to communicate with
181SQL Server. This may also be set using the B<$charset> environment variable.
182
183=item -k keywords
184
185Specifies a file containing a list of keywords to be used for keyword tab
186completion, if readline support has been compiled into sqsh. This file may also
187be set via the B<$keyword_file> variable, which defaults to B<$HOME>/.sqsh_words.
188
189=item -K keytab
190
191Kerberos support. Specify the keytab file name for DCE.
192
193See the Kerberos Support section below for details.
194
195=item -l debug_flags
196
197If sqsh has been compiled with -DDEBUG, this option may be used to turn on and
198off debugging options. See the B<$debug> variable, below.
199
200=item -L var=value
201
202Sets the value of B<$var> to I<value>. This may be used to set the value of any
203sqsh variable even if an explicit command line variable is supplied for setting
204the variable. The B<-L> flag may be used to set the value of non-configuration
205variables as well.
206
207=item -m style
208
209Changes the current display style to I<style>. Currently supported styles are
210B<horiz>, B<vert>, B<bcp>, B<csv>, B<html>, B<meta>, B<pretty> and B<none>. The
211current display style may also be set using the B<$style> variable or via the
212B<-m> flag to the B<\go> command.
213
214=item -n on|off
215
216Enables chained transaction mode on connect (if set to on). Chained transaction
217mode is also known as "AutoCommit off" mode.
218
219=item -N appname
220
221Set the application name sqsh uses to identify itself to the SQL server. The
222application name can be retrieved from the server using the column
223B<program_name> of the master.dbo.sysprocesses table. Defaults to I<sqsh-2.1.7>.
224
225=item -o filename
226
227Redirects all output to I<filename> rather than stdout.
228
229=item -p
230
231Display performance statistics upon completion of every SQL batch. This option
232may also be turned on via the B<$statistics> variable, or by supplying the B<-p>
233flag to the B<\go> command.
234
235=item -P [password | -]
236
237The Sybase I<password> for I<username> required to connect to I<server>
238(default, NULL). The I<password> may also be set via B<$password>. Supplying a
239password of '-' causes the password to be read from the first line of stdin.
240
241sqsh takes pains to hide the password from any user trying to view the command
242line used to launch sqsh, so using B<-P> should not constitute a security hole.
243Alternatively, you can store your default password in .sqshrc file which is not
244readable by anyone other than yourself. (chmod 600 .sqshrc)
245
246=item -Q value
247
248Query timeout value (equivalent to isql's -t option). If set, will timeout a
249long running query. Maps to the B<$query_timeout> variable.
250
251For example:
252
253    sqsh -SASE1502 -Usa -P -Q30
254    ASE1502.sa.master.1> cd tix
255    ASE1502.sa.tix.1> select count(*) from E_TIX;
256    Open Client Message
257    Layer 1, Origin 2, Severity 2, Number 63
258    ct_results(): user api layer: internal Client Library error:
259                Read from the server has timed out.
260    ASE1502: Query or command timeout detected, command/batch cancelled
261    ASE1502: The client connection has detected this 1 time(s).
262
263See also the B<$max_timeout> variable, which controls the number of times a
264timeout may occur on the current connection before the session is aborted.
265
266=item -r [sqshrc]
267
268Specifies an alternate I<.sqshrc> file to be processed, rather than the default.
269If no I<sqshrc> is supplied following B<-r>, then no initialization files are
270processed. This flag B<must> be the first argument supplied on the command line,
271all other instances will be ignored.
272
273=item -R server_principal
274
275Kerberos support: Specifies a I<server principal> to use for network (Kerberos)
276authentication, if the server name in the interfaces file differs from the real
277server name.
278
279See the Kerberos Support section below for details.
280
281=item -s colsep
282
283Causes the string I<colsep> to be used to delimit SQL column output columns,
284this defaults to " ".
285
286=item -S server | host:port[:filter]
287
288The name or the address of the Sybase I<server> to connect. The default of this
289is the external environment variable B<$DSQUERY>. If neither B<-S> nor
290B<$DSQUERY> is set then defaults to "SYBASE". This value may also be set via the
291internal variable B<$DSQUERY>. The servername must exist in the interfaces or
292sql.ini file. As an alternative it is also possible to specify the target
293server as B<host:port[:filter]> where I<host> may also be an IP address. Note
294that B<filter> may be defined in $SYBASE/$SYBASE_OCS/config/libtcl[64].cfg. For
295example:
296
297    [FILTERS]
298    ssl=libsybfssl.so
299    ssl64=libsybfssl64.so
300
301=item -t [filter]
302
303Enables filtering of command batches through an external program, I<filter>,
304and prior to being sent to the SQL Server. If I<filter> is not supplied, then
305B<$filter_prog> is used (default is 'm4 -'). This value may also be set via the
306B<$filter> and B<$filter_prog> variables.
307
308=item -T value
309
310Specifies the login timeout (similar to isql's -l flag). If set specifies the
311number of seconds I<sqsh> will wait before timing out a login request. Maps to
312the B<$login_timeout> variable.
313
314=item -U username
315
316The Sybase I<username> to connect to the database as, this defaults to the
317username of the user running I<sqsh>. The I<username> may also be set via the
318B<$username> variable.
319
320=item -v
321
322Displays the version number, B<$version>, and exits.
323
324=item -V [bcdimoqru]
325
326Kerberos support: Specify the security options to use.
327
328See the Kerberos Support section below for details.
329
330=item -w width
331
332The maximum output I<width> of a displayed result set, this defaults to your
333screen width in interactive mode.
334
335=item -X
336
337Initiates the login connection to the server with client-side password
338encryption (if supported). If either SQL Server does not recognize this option,
339or if the version of CT-Lib used to compile I<sqsh> does not support this
340option, then it will be ignored. This option may also be set using the
341B<$encryption> environment variable.
342
343=item -y directory
344
345Specifies a SYBASE I<directory> to use other than the value of B<$SYBASE> in
346order to find the interfaces file.
347
348=item -z language
349
350Specifies an alternate I<language> to display sqsh prompts and messages. Without
351the B<-z> flag, the server's default language will be used. This may also be
352set using the B<$language> variable.
353
354=item -Z [secmech|default|none]
355
356Kerberos support: Specify the security mechanism to use.
357
358See the Kerberos Support section below for details.
359
360=item args...
361
362If sqsh is run with the B<-i> flag specifying an input file to be processed
363(rather than initiating an interactive session), arguments may be supplied on
364the command line to be passed to the input file. These arguments may be accessed
365using the variables ${0}, ${1}, ... (see the B<Variables> section, below, for
366more information).
367
368=back
369
370=head2 Initialization
371
372Upon startup, sqsh initializes all internal environment variables, commands, and
373aliases to their default values, it then looks in the system-wide configuration
374file (usually /usr/local/etc/sqshrc), followed by a local configuration file
375B<$HOME>/.sqshrc (this may be overridden via the SQSHRC external environment
376variable). If this file is found it is executed just like a script would be
377using the B<-i> flag.
378
379The I<.sqshrc> file may contain anything that could normally be typed at the
380prompt, however it should be noted that at the time this file is read sqsh has
381yet to establish a connection to the database, however most commands that
382perform database activity, such as B<\go> will attempt to establish a database
383connection when executed (it may also prompt you for a password if necessary).
384Also, if database activity is required within this startup file, the B<\connect>
385command (see B<COMMANDS>, below) may be executed.
386
387After the I<.sqshrc> file has been executed, I<sqsh> then parses any command
388line options (thus any variables set in your I<.sqshrc> file may be overridden
389by command line options). Following that, if I<sqsh> is run in interactive mode
390(i.e. without B<-i> and if stdin is attached to a tty), it then looks for the
391file provided by the B<$history> variable and loads the contents of that file
392into the history buffers. (see B<BUFFERS>, below).
393
394Immediately prior to establishing a connection to the database (either during
395startup, or by an explicit B<\connect> or B<\reconnect> command), the file
396B<$HOME>/.sqsh_session is executed. The name of this file may be overridden
397using the B<$session> variable.
398
399=head2 Command line
400
401When a line is first read by I<sqsh>, the first word is separated from the line.
402This word is then expanded of all variables (see B<Variable Substitution>,
403below), followed by command expansion (see B<Command Substitution>, below). The
404first word of the resulting string is then analyzed to see if it is either a
405valid I<sqsh> command or alias.
406
407The I<sqsh> command line follows many of the same rules as Bourne shell,
408allowing file redirection, pipelining, command substitution, and back-grounding
409via the same syntax.
410
411=head2 Comments
412
413Any line beginning with a B<#> followed by a non-alphanumeric character (any
414character other than 0-9, a-z, A-Z, and _) causes the entire line to be ignored.
415Because of the possible collision with T-SQL session specific temp-table names,
416the line will not be ignored if the first character following the B<#>, is
417alphanumeric.
418
419=head2 Quoting
420
421Quoting is used to prevent the interpretation of special keywords or characters
422to sqsh, such as white-space, variable expansion, or command substitution. There
423are three types of quoting, I<escape>, I<single-quotes>, and I<double-quotes>.
424
425Enclosing characters in single quotes preserves the literal interpretation of
426each character contained within the quotes. A single quote may not appear within
427single quotes, even when preceded by an escape. For example:
428
429    1> \echo I can not expand '$username'
430
431outputs
432
433    I can not expand $username
434
435The characters \\ are used to escape the meaning (and thus prevent the
436interpretation) of the character immediately following them. The \ character
437itself may be escaped. For example:
438
439    1> \echo I can\\'t expand '$username'
440
441outputs
442
443    I can't expand $username
444
445The escape character may also be used to escape a new-line in order to perform a
446line continuation, in this case the new-line is discarded and the continued line
447is automatically appended to the previous line, for example:
448
449    1> \echo Hello \\
450    --> World!
451    Hello World!
452
453Enclosing characters in double quotes preserves the literal meaning of all
454characters within them with the exception of B<$>, B<'>, and B<\\>. A double
455quote may be contained within double quotes by escaping it.
456
457    1> \echo "\\"I can't deny it, I like $username\\", she said"
458
459prints out
460
461    "I can't deny it, I like gray", she said
462
463
464=head2 Expansion
465
466After a line of input has been read, I<sqsh> attempts to expand the line of any
467aliases (see B<Aliasing>, below), following that it attempts to determine if the
468line begins with a command keyword. Once a line has been determined to contain a
469command name it has three types of expansion performed to it: I<variable
470substitution>, followed by I<command substitution> respectively. Finally, if a
471tilde was provided on the command line, then I<tilde expansion> will be performed
472and the B<~> will be substituted with the corresponding B<HOME> directory name.
473
474    1> \echo ~sybase/err.log
475
476may result in I</home/sybase/err.log> for example.
477
478    1> exec sp_helpdb
479    2> go > ~/db.log
480
481may result in a file I</export/home/dba/db.log> for example, depending on the
482Unix login and the exact OS you are using.
483Following this expansion the command line is separated into words and the
484command is executed.
485
486=head2 Variable Substitution
487
488The character $ is used to indicate variable substitution or expansion within a
489word. These variables may be assigned values by the B<\set> command like so:
490
491    1> \set name=value
492
493I<name> may be a character or underscore followed by any combination of
494characters, digits, or underscore, and may not contain any special characters,
495such as (') and ("). The restriction on the first character being a digit is
496introduced because SQL allows the representation of money data types as $nn.nn
497where n is a digit.
498
499I<value> may contain anything, however if it is to include white-space, then it
500must be quoted (see B<Words & Quoting>, above). Note that in order to prevent
501the expansion of a variable use either single quotes, or two \'s, like thus:
502
503    1> \echo \\$name
504    $name
505
506Variables may be referenced in one of two ways:
507
508$variable In this manner all characters, digits, and underscores are treated as
509the I<name> of the variable until another type of character is reached (either a
510special character, or a white-space). ${variable} The braces are required only
511when I<variable> is followed by a letter, digit, or underscore that is not to be
512interpreted as part of its name. Note that the same effect may be achieved using
513double quotes.
514
515It should be noted that because the variables are expanded prior to breaking the
516command line into words, if the contents of the variable contain white spaces,
517they are treated as significant by the parser. In the following example:
518
519    1> \set x="1 2 3"
520    1> \echo $x
521
522the B<\echo> command receives three arguments, "1", "2", and "3", although it
523looks as if only one argument was passed to it. This behavior is consistent with
524most shells (such as csh, bourne shell, etc.).
525
526=head2 Command Substitution
527
528I<Sqsh> supports a second form of expansion called I<command substitution>. This
529form of expansion substitutes a command on the command line with the output of
530the external UNIX command. This expansion may be achieved by placing the command
531line to be executed in back-quotes (`). For example:
532
533    1> \set password=`/sybase/bin/getpwd $DSQUERY`
534    1> \echo $password
535    ilikepickles
536
537This example, the external program B</sybase/bin/getpwd> is executed with the
538current contents of the B<$DSQUERY> environment variable, the entire expression is
539then replaced with the output of B<getpwd (ilikepickles)> prior to executing the
540B<\set> command. By default, the output of the substituted command is first
541broken into words according to the contents of the B<$ifs> variable prior to
542assembling together back into the command line. So, by overriding the contents
543of B<$ifs> you may affect the behavior of the substitution process.
544
545For example:
546
547    1> \set ifs=":"
548    1> \echo `echo hello:how:are:you`
549    hello how are you
550
551This mechanism is frequently useful for parsing input files, such as
552B</etc/passwd> into fields.
553
554=head2 Input/Output Redirection
555
556As with standard Bourne shell (and most other shells, for that matter), a
557command's input and output may be redirected using a special notation
558interpreted by the shell. The following may appear anywhere on the command line,
559but only redirection that is specified I<prior> to a pipe (|) actually has any
560effect on the behavior of internal sqsh commands (refer to B<Pipes>, below).
561
562=over 4
563
564=item <word
565
566Use the file I<word> as the standard input for the command. Typically very few
567I<sqsh> commands actually read anything from stdin, so this will usually have no
568effect (see the B<\loop> command).
569
570=item [n]>word
571
572Associate the output of file descriptor I<n> (stdout, by default) with file
573I<word>. If this file does not exist it is created; otherwise it is truncated to
574zero length.
575
576=item [n]>>word
577
578Append the output of file descriptor I<n> (stdout, by default) to file I<word>,
579creating it if it does not exist.
580
581=item [m]>&n
582
583Redirect the output of file descriptor I<m> (stdout by default), to same output
584as file descriptor I<n>. The order in which redirections are specified on the
585command line is significant, as the redirections are evaluated left-to-right.
586For example:
587
588    1> select * from select /* syntax error */
589    2> \go >/tmp/output 2>&1
590
591This statement first redirects the standard output of the B<\go> command to the
592file I</tmp/output>, then redirects the stderr to the same file. So, when the
593commands fails, the error output will be found in the file I</tmp/output>.
594
595However, by changing the order of redirection, you can completely change the
596meaning:
597
598    1> select * from select
599    2> \go 2>&1 >/tmp/output
600    Msg 156, Level 15, State 1
601    Server 'SQSH_TEST', Line 1
602    Incorrect syntax near the keyword 'select'.
603
604In this case, error output will be sent to stdout, while what would have gone to
605stdout is redirected to I</tmp/output> (in this case I</tmp/output> will be
606empty).
607
608=back
609
610Please read the section on B<Background Jobs>, below, for detailed info on the
611interaction between file redirection and background jobs.
612
613=head2 Pipes
614
615A I<pipeline> is a sequence of one or more commands separated by a '|', each
616command using the stdout of the preceding program for its own stdin. However the
617first command in the I<pipeline> must be a sqsh command, and all other commands
618must be external (or UNIX) programs. Any sqsh command may be run through a
619pipeline, although for many of them (such as the B<\set> command) it doesn't
620really make any sense to do this. The following is an example of a I<pipeline>:
621
622    1> select * from syslogins
623    2> \go | more
624
625This command causes the result set generated by the B<\go> command to be sent to
626the B<more(1)> program, which then sends it to your screen, pausing at each
627screen full of data (this is the primary reason that I wrote sqsh).
628
629There are several peculiarities in the way in which sqsh deals with I<pipelines>
630as opposed to the way in which standard Bourne shell treats them.
631
632Everything following the first occurrence of a pipe (|) character is broken into
633white-space delimited words, including such special shell commands as '2>&1'
634and other occurrences of pipes. If there are any variables contained in these
635words they are expanded following the same quoting rules as described in
636B<Words & Quoting>, above, with the one exception that all quotes are left in
637place. These words are then reassembled into a single string and shipped off to
638/bin/sh for processing.
639
640In short, sqsh makes no attempt to interpret what follows the first pipe,
641instead it is shipped off to a "real" shell to do the work. The rationale behind
642this is that I was lazy and didn't feel like writing all of the same bizarre
643variable handling, &&'ing, ||'ing, grouping, and variable expansion rules
644that Bourne shell supports, and instead I let Bourne do the dirty work.
645
646The advantage of this method is that you can do some very complex stuff after
647the pipeline, such as:
648
649    1> select * from syscolumns
650    2> \go | (cd /tmp; compress -c > sysolumns.Z)
651
652Not that I can think of any real reason to do this...but you can if you want to.
653
654=head2 Background Jobs
655
656Backgrounding provides a mechanism whereby you may run any sqsh command as a
657background process and continue working while it runs. Sqsh offers two types of
658backgrounding:
659
660=over 4
661
662=item Deferred
663
664In this mode sqsh redirects all output of the background job to a temporary file
665(located in the directory B<$tmp_dir>) while the job is running, so that the
666output is not intermixed with what you are currently working on. When the job
667completes you are notified of the process completion and the output may be
668viewed using the B<\show> command.
669
670=item Non-Deferred
671
672This corresponds to the common idea of a background process under UNIX. In this
673mode the output of the job is not implicitly redirected for you, and thus may
674become intermingled with what you are currently working. The mode selection you
675choose is selectable via the B<$defer_bg> variable (which defaults to '1', or
676'On'). Typically the only reason to not use I<deferred> mode is to prevent
677large result sets from filling up your file system.
678
679=back
680
681To specify that a job be run in the background, simply append a & to the end of
682the command line, as:
683
684    1> sp_long_arduous_proc 1, 30
685    2> \go &
686    Job #1 running [xxxx]
687    1>
688
689When sqsh encounters the & on the end of the command line it spawns a child
690process (with a Unix process id of I<xxxx>) then the child process calls the
691B<\go>. B<\go> command then establishes a new connection to the database (using
692the current values of the B<$DSQUERY>, B<$username>, B<$password> variables)
693and executes the shown query. While the job is executing the commands B<\jobs>,
694B<\wait> and B<\kill> may be used to monitor or alter a currently running job
695(see section B<COMMANDS>, below). When any job completes sqsh will display a
696notification, such as:
697
698    1> select count(*) from <return>
699    Job #1 complete (output pending)
700    2>
701
702When a job completes, if it had no output, it is immediately considered
703terminated and will not show up in the current list of running jobs. However if
704the complete job has pending output, it will continue to be displayed as a
705running job (with the B<\jobs> command) until a B<\show> is used to display the
706output of the job.
707When you exit your parent sqsh session and there are background jobs active then
708a message is shown: B<You have running jobs or pending job output>.
709You have to process all the jobs first before being able to exit sqsh.
710
711There is a known bug with job backgrounding when used in conjunction with pipes,
712please refer to the B<BUGS> section at the end of the manual.
713
714=head2 Buffers
715
716In normal B<isql> only two buffers are maintained; the buffer into which you are
717currently typing, and a buffer that contains the last batch executed (this is
718kept around for when you run 'vi', or 'edit').
719
720Sqsh maintains several distinct sets of buffers:
721
722B<Work Buffer>: This buffer corresponds directly to the B<isql> work buffer. It
723is the buffer into which you enter the current batch prior to sending it to the
724database.
725
726B<History Buffer>: This is actually a chain of 0 or more buffers (configurable
727by the B<$histsize> variable) of the last B<$histsize> batches that have been
728run. This buffer is only maintained when sqsh is run in interactive mode; that
729is, batches executed using the B<-i> flag, or executed via redirection from the
730UNIX prompt will not be maintained in history (after all, they are already in a
731file somewhere).
732
733If the variable B<$histsave> is True (see section B<SPECIAL VARIABLES>) and sqsh
734is in interactive mode, then the current history buffer is written to
735B<$HOME>/.sqsh_history when you exit. This file is then read back into sqsh the
736next time it is started in interactive mode.
737
738B<Named Buffers>: At any time during a session the B<Work Buffer>, or any of the
739B<History Buffers> may be copied into a named buffer using the B<\buf-copy>
740command (see section B<COMMANDS>, below). These buffers are lost when you exit
741(however you may use the B<\buf-save> command to save named buffers to a file).
742
743=head3 Buffer Short-Hand
744
745Many commands allow all of these buffers to be referenced in a short-hand
746fashion, very similar to the way that B<csh(1)> references its commands history.
747Any of these shorthands may be used for any I<buffer> parameter described in the
748B<COMMANDS> section:
749
750=over 4
751
752=item !.
753
754The current work buffer.
755
756=item !!
757
758The last command executed (note, this is not available in non-interactive mode
759as it does not maintain a history).
760
761=item !+
762
763The next available history entry. This is a write-only buffer, so typically only
764applies to such commands as B<\buf-copy>.
765
766=item !n
767
768Refers to history #n. Each time an entry is written to history it is assigned an
769increasing number from the last entry, with this short-hand you may reference
770any given history.
771
772=item !buf_name
773
774Just for consistency this is supplied as a reference to named buffer
775I<buf_name>, however I<buf_name> without the leading '!' is also considered
776correct.
777
778=item buf_name
779
780Refers to the named buffer I<buf_name>.
781
782=back
783
784=head3 Variables
785
786Variables may also be contained within work buffers. Under these circumstances
787the variables remain unexpanded until the buffer is sent to the database (via
788the B<\go> command), during which time they are expanded and replaced within the
789buffer. This behavior may be altered via the B<$expand> variable.
790(see B<Special Variables>, below).
791
792The following is an example of using variables within a buffer:
793
794    1> \set table_name=syscolumns
795    1> select count(*) from $table_name
796    2> \go
797
798This is the equivalent of performing the query:
799
800    1> select count(*) from syscolumns
801    2> \go
802
803directly. Typically this feature is useful for reusing large complex B<where>
804clauses, or long column names.
805
806Quoting rules apply the same in SQL buffers as they do in command lines. That
807is, any variables contained within double quotes (") are expanded and variables
808contained within single quotes (') are left untouched. Thus:
809
810    1> select "$username", '$username'
811    2> \go
812
813yields the results
814
815    ---- ---------
816    gray $username
817
818
819=head3 Command Substitution
820
821As with the command line, the output of UNIX commands may also be substituted
822within a SQL buffer upon execution (once again, only if the B<$expand> variable
823is set to 1, or true). In this circumstance the command contained within back
824quotes (`) is replaced with its output prior to forwarding the buffer to SQL
825server. For example:
826
827    1> select count(*) from `echo syscolumns`
828    2> \go
829
830Causes the strings 'echo syscolumns' to be replaced by the word
831I<syscolumns> prior to executing the command. It should be noted that the
832contents of the substituted command are only executed at the time of the B<\go>
833command, not when the line of SQL is input.
834
835=head2 Flow-of-Control
836
837New with version 2.0 of sqsh, is the ability to perform basic flow-of-control
838and functions using the B<\if>, B<\while>, B<\do>, and B<\func> commands.
839
840=head3 Blocks & SQL Buffers
841
842All sqsh flow-of-control commands are block-based. That is, if the test
843expression of the command is met, then a block of sqsh-script will be executed.
844For example, the definition of the B<\if> command is:
845
846    \if expression
847        block
848    \fi
849
850This I<block> may be any number of lines of sqsh commands, SQL, or
851flow-of-control statements to be executed if the I<expression> evaluates to a
852success condition (0).
853
854Each I<block> has its own SQL buffer for the duration that the I<block> is
855executed. That is, the following statements:
856
857    1> /*
858    2> ** IMPROPER USAGE OF IF BLOCK
859    3> */
860    4> select count(*) from
861    5> \if [ $x -gt 10 ]
862    6>     sysobjects
863    7> \else
864    8>     sysindexes
865    9> \fi
866    5> go
867
868will yield:
869
870    Msg 102, Level 15, State 1
871    Server 'bps_pro', Line 1
872    Incorrect syntax near 'from'
873
874because the string 'sysobjects' or 'sysindexes' were inserted into their
875own SQL buffers. These buffers are discarded as soon as the end of the block was
876reached, and since a B<\go> command was not contained within the block, no
877additional errors were generated.
878
879Thus, the correct way to write the above expression would be:
880
881    1> /*
882    2> ** PROPER USAGE OF IF BLOCK
883    3> */
884    4>  \if [ $x -gt 10 ]
885    5>     select count(*) from sysobjects
886    6>     go
887    7> \else
888    8>     select count(*) from sysindexes
889    9>     go
890    10> \fi
891
892or, even:
893
894    1> /*
895    2> ** PROPER USAGE OF IF BLOCK
896    3> */
897    4>  \if [ $x -gt 10 ]
898    5>     \set table_name=sysobjects
899    6> \else
900    7>     \set table_name=sysindexes
901    8> \fi
902    4> select * from $table_name
903    5> go
904
905Also, note that the line number displayed in the sqsh prompt resets to the
906current position in the outer SQL buffer after reaching the B<\fi> terminator.
907
908=head3 Expressions
909
910All flow-of-control statements in sqsh take an I<expression> to determine which
911I<block> of code to execute. Just like UNIX's Bourne Shell, this I<expression>
912is simply an operating system program that is executed by sqsh. If the command
913returns a success status (calls exit(0)), then it is considered successful.
914
915For example, with following statement:
916
917    \while test $x -lt 10
918        block
919    \done
920
921will execute the contents of I<block> while the current value of $x is less than
92210. Note that 'test' is a standard UNIX program to perform basic string or
923numeric comparisons (among other things). Also, unlike many shells, sqsh has no
924built-in version of 'test'.
925
926Sqsh does, however, support the standard short form of 'test':
927
928    \while [ $x -lt 10 ]
929        block
930    \done
931
932With this expression the open brace ('[') is replaced by the sqsh parser
933with 'test', and the close brace (']') is discarded.
934
935=head3 Unsupported Expressions
936
937Currently sqsh does not support the standard shell predicate operators '&&'
938and '||'. These can be performed like so:
939
940    \if sh -c "cmd1 && cmd2"
941        block
942    \done
943
944
945=head4 \if statement
946
947The B<\if> command performs conditional execution of a sqsh I<block> based upon
948the outcome of a supplied expression:
949
950    \if expr1
951        block1
952    \elif expr2
953        block2
954    \else
955        block3
956    \fi
957
958In this example, if expression I<expr1> evaluates to true, then the block
959I<block1> is evaluated. Otherwise, if the expression I<expr2> evaluates to true,
960then block I<block2> is evaluated. Finally, if all other tests fail I<block3> is
961evaluated.
962
963Note that, unlike Bourne Shell, every B<\if> command must be accompanies by a
964trailing B<\fi> statement. Also the sqsh parser is not terribly intelligent: The
965B<\else> and B<\fi> statements must be the only contents on the line in which
966they appear, and they may not be aliased to another name.
967
968=head4 \while statement
969
970The B<\while> command executes a I<block> of sqsh code for the while a supplied
971expression remains true.
972
973    \while expr
974        block
975    \done
976
977In this example, while the expression I<expr> evaluates to true, then the block
978I<block> is evaluated.
979
980The B<\break> statement may be used to break out of the inner-most B<\while> or
981B<\for> loop (more on B<\for> below).
982
983=head4 \for statement
984
985The B<\for> command executes a I<block> of sqsh code for each I<word> supplied:
986
987    \for var in word ...
988        block
989    \done
990
991For each I<word> supplied, the value of the variable B<$var> is set to the word
992and the I<block> of code is executed. Execution ends when there are no more
993words in the list.
994
995As with B<\while> the B<\break> statement may be used to break out of the
996inner-most execution loop.
997
998=head4 \do command
999
1000The B<\do> command is kind of a cross between a statement and a command.
1001
1002It is a form of B<\go> (see below for details on the B<\go> command) in which a
1003I<block> of sqsh code may be executed for each row of data returned from the
1004query. When the I<block> is executed, special sqsh variables #[0-9]+ (a hash
1005followed by a number) may be used to reference the values in the returned query.
1006For example the following command:
1007
1008    select dbid, name from master..sysdatabases
1009    \do
1010        \echo "Checkpointing database #2, dbid #1"
1011        use #2
1012        go
1013        checkpoint
1014        go
1015    \done
1016
1017would cause a CHECKPOINT command to be issued in each database on the server.
1018
1019=head4 Command line options
1020
1021The B<\do> command establishes a new connection to be used by the I<block> of
1022code when executed. By default, this connection is established to the current
1023server (the current setting of B<$DSQUERY>), using the current username
1024(B<$username>) and the current password (B<$password>). This behavior may,
1025however, be overridden using command line options:
1026
1027=over 4
1028
1029=item -D database
1030
1031Establishes the connection to the database as the supplied I<database>.
1032
1033=item -U username
1034
1035Establishes the connection to the server as the supplied I<username>.
1036
1037=item -P password
1038
1039Establishes the connection to the server using the supplied I<password> (which
1040is hopefully a valid password for the supplied I<username>).
1041
1042=item -S server | host:port[:filter]
1043
1044Establishes the connection to the supplied I<server>.
1045
1046=item -n
1047
1048Do not create a connection for use by the B<\do> loop. This flag is mutually
1049exclusive with the above flags. With this flag enabled, attempts to perform
1050database commands within the I<block> will generate a flurry of CT-Library
1051errors.
1052
1053=back
1054
1055=head4 Column variables
1056
1057As mentioned above, the values of the columns in the current result set may be
1058determined using the special #[0-9]+ variables. Thus, the variable #1 would
1059contain the value of column number one of the current result set, and #122 could
1060contain the value of the 122'nd column (column numbers begin at 1).
1061
1062In the case of nested B<\do> loops, values in previous nesting levels may be
1063referred to by simply appending an addition '#' for each previous nesting
1064level, like so:
1065
1066    select id, name from sysobjects
1067    \do
1068        select name, indid from sysindexes where id = #1
1069        \do
1070            \echo "Table ##2 (objid ##1) has index #1"
1071        \done
1072    \done
1073
1074obviously, this isn't the way you would do this query in real life, but you
1075get the idea.
1076
1077When expanding columns with NULL values, the column variable will expand to an
1078empty string (''). Also, references to non-existent columns, such as #0,
1079will result in an empty string ('').
1080
1081As with regular sqsh variables (those referenced with a '$'), column
1082variables will not be expanded when contained within single quotes.
1083
1084=head4 Aborting
1085
1086If the B<\break> or B<\return> commands are issued during the processing of a
1087B<\do> loop, the current query will be canceled, the connection used by the loop
1088will be closed (unless the B<-n> flag was supplied) and the B<\do> loop will
1089abort.
1090
1091=head4 \func command
1092
1093The B<\func> command is used to define a reusable block of sqsh code as a
1094function. Functions are defined like so:
1095
1096    \func stats
1097        \if [ $# -ne 1 ]
1098            \echo "use: stats [on | off]"
1099            \return 1
1100        \fi
1101        set statistics io ${1}
1102        set statistics time ${1}
1103        go
1104    \done
1105
1106In this example a new function is established called I<stats> that expects a
1107single argument, either "on" or "off". Using this argument, I<stats> will enable
1108or disable time-based and I/O-based statistics.
1109
1110Once established, the function may be called like so:
1111
1112    \call stats on
1113
1114Causing all instances of ${1} to be replaced with the first command line
1115argument to I<stats>.
1116
1117=head4 Command line options
1118
1119Currently only one command line argument is available to the B<\func> command.
1120
1121=over 4
1122
1123=item -x
1124
1125Causes the function to be exported as a I<sqsh> command. That is, the function
1126may be invoked directly without requiring the B<\call> command. This behavior is
1127optional because command names can potentially conflict with T-SQL keywords.
1128When using this flag it is recommended that you prepend a backslash (\) to your
1129function name.
1130
1131=back
1132
1133=head4 Function variables
1134
1135As shown in the example above, several special variables are available for use
1136within the body of the function. These are:
1137
1138=over 4
1139
1140=item $#
1141
1142Expands to the number of arguments supplied to the function or script when
1143invoked.
1144
1145=item $*
1146
1147Expands to the complete list of arguments supplied to the function or script
1148when invoked.
1149
1150=item ${0}..${N}
1151
1152Expands to positional arguments to the function. ${0} is the name of the
1153function or the script file being invoked, ${1} is the first argument,
1154${2} the second and so-on, up to argument I<N>. Note that, unlike most shells,
1155sqsh requires that function arguments be referred to using the special curly
1156brace syntax (${1}, rather than $1). The reason for this is that $1 is a valid
1157MONEY value and using the curly braces gets rid of this ambiguity.
1158
1159=item $?
1160
1161After the invocation of a function, this will contain its return value (see
1162below).
1163
1164=back
1165
1166=head4 Return value
1167
1168A value may be returned from a function via the B<\return> command.
1169
1170Like so:
1171
1172    \return N
1173
1174Where I<N> is a positive value. This return value is available to the caller of
1175the function via the B<$?> variable. As convention, a return value of 0 is used
1176to indicate a success.
1177
1178If B<\return> is not explicitly called, the default return value is the current
1179value of the B<$?> variable (which is set to 0 upon entry of the function).
1180Thus, if any SQL statements are invoked within the function, the default return
1181value of B<$?> will be the last error code returned during the processing of the
1182SQL statement.
1183
1184=head2 Kerberos Support
1185
1186Starting with version 2.1.6, I<sqsh> provides the same command line options as
1187I<isql> to handle Kerberos network authentication.
1188
1189In version 2.1.5 experimental Kerberos support was added using the -K and -R
1190options. -K was merely a switch to set Kerberos on. In sqsh 2.1.6 a more
1191advanced implementation of network authentication is introduced, although still
1192experimental.
1193
1194By using the parameters -K, -R, -V, -Z you can make use of your defined network
1195security settings (libtcl.cfg). The named options are identical to the ones
1196defined for I<isql>.
1197
1198=over 4
1199
1200=item -K keytab_file
1201
1202Keytab_file name for DCE.
1203
1204=item -R server_principal
1205
1206Server principal name when servername specified in interfaces differs from the
1207real server name.
1208
1209=item -V [bcdimoqru]
1210
1211Specify security options to use with the security mechanism. Each character
1212stands for a specific security service.
1213
1214=item -Z [secmech|default|none]
1215
1216Request a security mechanism defined for Kerberos, DCE or PAM in your
1217libtcl.cfg file. Use B<secmech> to specify the name of a SECURITY entry or
1218B<default> for the first available entry in libtcl.cfg. B<None> must be
1219specified to disable network authentication or reset possible existing
1220values in variables B<$secmech> or B<$secure_options>.
1221
1222=back
1223
1224For example, connecting to a server using Kerberos (which happens to be
1225the default, i.e. first entry in libtcl.cfg [SECURITY] tab in this example):
1226
1227    ~$ sqsh -SSYB1502 -Uuser1 -RFC6A1502 -Z
1228    \connect: Network authenticated session expires at:
1229            16 Feb 2010 15:28:39 (11764 secs)
1230    SYB1502.user1.master.1> select @@servername,@@authmech,
1231                                 show_sec_services();
1232    ----------------  -----------  ----------------------------------
1233    FC6A1502          kerberos     unifiedlogin delegation mutualauth
1234                                 integrity confidentiality
1235                                 detectreplay detectseq
1236
1237Note that the real name of the server (@@servername) differs from the server
1238name in the interfaces file, so we have to specify the principal name through
1239the B<-R> parameter.
1240When you do not specify the B<-V> parameter together with B<-Z>, all available
1241security options will be enabled. When B<-V> is specified without any security
1242service options, only option B<u> for Network Authentication will be implicitly
1243set and the default security mechanism will be used if B<-Z> is not specified.
1244
1245    [user1@linux-fc6a ~]$ sqsh -SFC6A1502 -Uuser1 -V
1246    Open Client Message
1247    Layer 7, Origin 9, Severity 5, Number 1
1248    ct_connect(): security service layer: internal security control
1249                layer error:
1250                Security service provider internal error -1765328352
1251                occurred.
1252    [user1@linux-fc6a ~]$ kinit
1253    Password for user1@LOCALDOMAIN:
1254    [user1@linux-fc6a ~]$ sqsh -SFC6A1502 -Uuser1 -V
1255    \connect: Network authenticated session expires at:
1256            16 Feb 2010 15:28:39 (10964 secs)
1257    FC6A1502.user1.master.1>
1258
1259When the connection succeeds, I<sqsh> will store the real name of the security
1260mechanism in the variable B<$secmech>. For example: "\echo $secmech" may show
1261I<csfkrb5>. The parameter B<-V> takes a list of characters from the possible
1262values of I<bcdimoqru>. The option B<u> enables Network Authentication, is the
1263default and will allways be set when using B<-V> or B<-Z>, specified or not.
1264
1265    b - chanbinding     : Channel binding
1266    c - confidentiality : Data confidentiality service
1267    d - delegation      : Allow delegated credentials
1268    i - integrity       : Data integrity service
1269    m - mutualauth      : Mutual authentication for connection
1270                          establishment
1271    o - dataorigin      : Data origin stamping service
1272    q - detectseq       : Out-of-sequence detection
1273    r - detectreplay    : Data replay detection
1274    u - unifiedlogin    : Network Authentication
1275
1276Please check master.dbo.syssecmechs for available services. Non-existing or not
1277supported services supplied with B<-V> are silently ignored. If you specify
1278B<-V> and/or B<-Z>, I<sqsh> assumes network authentication is tried and no
1279password is required.
1280
1281If you have a network authenticated connection and want to \reconnect using
1282normal ASE authentication with username and password, you have to reset the
1283network authentication variables by specifying -Znone
1284
1285For example:
1286
1287    [user1@linux-fc6a ~]$ sqsh -SFC6A1502 -Uuser1 -V
1288    \connect: Network authenticated session expires at:
1289            16 Feb 2010 15:28:39 (10764 secs)
1290    FC6A1502.user1.master.1> \echo $secmech csfkrb5
1291    FC6A1502.user1.master.1> \reconnect -SASE1502 -Usa -Psybase
1292    Open Client Message
1293    Layer 7, Origin 9, Severity 5, Number 8
1294    ct_connect(): security service layer: internal security control
1295                layer error:
1296    Consistency checks performed on the credential failed
1297    (minor status 0).
1298    FC6A1502.user1.master.1> \reconnect -SASE1502 -Usa -Psybase -Znone
1299    ASE1502.sa.master.1>
1300
1301The first \reconnect fails because sqsh still wants to try network
1302authentication. However, no user principal for 'sa' exists and no ticket is set
1303and thus the connection fails. The second B<\reconnect> succeeds as the -Znone
1304option reset appropriate variables.
1305If the Kerberos ticket is renewed with B<kinit> or any other client tool, the
1306I<sqsh> session must perform a B<\reconnect> to refresh the credentials and
1307to prevent a premature session abort. With the command B<\snace> you can request
1308for the session expiration interval. Depending on the security services that are
1309set, the database connection may be closed without warning as soon as the ticket
1310expires.
1311
1312See chapter 16 "External Authentication" from the Sybase System Administration
1313Guide volume 1 for more information on Kerberos network authenticationi, e.a.
1314
1315=head1 COMMANDS
1316
1317=head2 Read-Eval-Print
1318
1319The read-eval-print loop is the heart of the sqsh system and is responsible for
1320prompting a user for input and determining what should be done with it.
1321Typically this loop is for internal use only, however they are open to the user
1322because there are some creative things that can be done with them.
1323
1324=over 4
1325
1326=item \loop [-i] [-n] [-e sql] [file]
1327
1328The B<\loop> command reads input either from a file, a supplied SQL statement,
1329or from a user (see the options below), determining whether the current line is
1330a portion of a T-SQL statement or a sqsh command, and performing the appropriate
1331action. When run in an interactive mode B<\loop> is also responsible for
1332displaying the current prompt (see B<$prompt> below).
1333
1334B<\loop> completes when all input has been depleted (end-of-file is encountered)
1335or when a command, such as B<\exit> requests that B<\loop> exit.
1336
1337=over 4
1338
1339=item -i
1340
1341Normally, if I<file> is supplied and does not exist, B<\loop> will return with
1342an error condition, usually causing sqsh to exit. By supplying the B<-i> flag,
1343control will be returned to the calling loop as if end-of-file had been reached
1344(that is, with no error condition).
1345
1346=item -n
1347
1348By default, B<\loop> will automatically attempt to connect to the database if a
1349connection has not already been established via the B<\connect> command. The
1350B<-n> flag disables this behavior allowing B<\loop> to process commands that do
1351not require database support.
1352
1353=item -e sql
1354
1355Causes B<\loop> to process the contents of I<sql> as if the user had typed it at
1356the prompt and an implicit call to B<\go> is automatically appended to the
1357statement. If multiple instances of B<-e> are supplied, they are all sent as a
1358single batch to the SQL Server for processing. This option may not be used in
1359combination with a I<file> name as well.
1360
1361=item file
1362
1363Specifies the name of a I<file> to be used as input rather than reading input
1364from the user or from the B<-e> flag.
1365
1366=back
1367
1368=back
1369
1370=head3 Database Access
1371
1372Given the size and complexity of sqsh (just look at the length of this man
1373page), it is amazing how few database manipulation commands that there actually
1374are. The following are commands that affect or use the current database
1375connection:
1376
1377=over 4
1378
1379=item \connect [-A packet size] [-c] [-D db] [-G tds version} [-S srv] [-U user] [-P pass] [-I ifile] [-J charset] [-K keytab] [-R server_principal] [-n] [-N appname] [-Q query_timeout] [-T login_timeout] [-V [bcdimoqru]] [-X] [-z language] [-Z [secmech|default|none]]
1380
1381This command is used primarily for internal use to establish a connection to a
1382database. If a connection is already established it has no effect, however if a
1383connection has not been established and B<$password> has not been supplied, then
1384the password is requested and a connection is established. B<\connect> accepts
1385the following parameters:
1386
1387=over 4
1388
1389=item -A
1390
1391Specifies the size of the network TDS packets used to communicate with the SQL
1392server. This value must be between 512 and 8192, and be a multiple of 512. Check
1393your SQL Server configuration to determine supported packet sizes. This value
1394may also be specified at run-time using the $packet_size variable.
1395
1396=item -c
1397
1398By default, the B<\connect> command uses the contents of B<$database> to
1399determine the database context that should be used upon establishing the
1400connection (this is used by B<\reconnect> to preserve the current database
1401context upon reconnection). The B<-c> flag suppresses this behavior and the
1402default database context of login is used instead.
1403
1404=item -D db
1405
1406Causes B<\connect> to attempt to automatically switch the database context to
1407I<db> after establishing the connection.
1408
1409Using this flag is identical to setting the B<$database> variable prior to
1410establishing the connection.
1411
1412=item -G tds version
1413
1414Set the TDS version to use. See the global startup parameter -G for more
1415information on TDS version.
1416
1417=item -S srv | host:port[:filter]
1418
1419The name or address of the Sybase I<server> to connect, this defaults to
1420B<$DSQUERY> if not supplied.
1421
1422=item -U user
1423
1424The Sybase I<user> to connect to the database as, this defaults to B<$username>
1425variable if not supplied.
1426
1427=item -P pass
1428
1429The I<password> for I<user> required to connect to I<server>. This defaults to
1430B<$password> if not supplied.
1431
1432=item -I ifile
1433
1434The full path of an alternate Sybase I<interfaces> file to use.
1435
1436=item -J charset
1437
1438The name of the client character set to communicate with the server.
1439
1440=item -K keytab_file
1441
1442Used for DCE user authentication.
1443
1444=item -R principal_name
1445
1446Use for Kerberos user authentication to specify the name of the server
1447principal when the name differs from the B<$DSQUERY> value.
1448
1449See also the discussion on Kerberos support.
1450
1451=item -n
1452
1453Specifies that the connection must use ANSI compliant chained mode.
1454
1455=item -N appname
1456
1457Specify the application name the server will use for program_name in the
1458sysprocesses table.
1459
1460=item -Q query_timeout
1461
1462Set a query timeout period in seconds.
1463
1464=item -T login_timeout
1465
1466Specifies a maximum wait time for session setup.
1467
1468=item -V [bcdimoqru]
1469
1470Security services used for Kerberos support and other security mechanisms.
1471
1472=item -X
1473
1474Initiates the login connection to the server with client-side password
1475encryption (if supported). If either SQL Server does not recognize this option,
1476or if the version of CT-Lib used to compile I<sqsh> does not support this
1477option, then it will be ignored. This option may also be set using the
1478B<$encryption> environment variable.
1479
1480=item -z language
1481
1482Specifies an alternate language to display sqsh prompts and messages. Without
1483the -z flag, the server's default language will be used. This may also be set
1484using the $language variable.
1485
1486=item -Z [secmech|default|none]
1487
1488Specifies the security mechanism to use for user authentication. For example
1489csfkrb5 for Kerberos support.
1490
1491=back
1492
1493=item \reconnect [-A packet size] [-c] [-D db] [-G tds version} [-S srv] [-U user] [-P pass] [-I ifile] [-J charset] [-K keytab] [-R server_principal] [-n] [-N appname] [-Q query_timeout] [-T login_timeout] [-V [bcdimoqru]] [-X] [-z language] [-Z [secmech|default|none]]
1494
1495The B<\reconnect> command may be used to force a reconnection to the database
1496using a new username, server name, or password (if desired). If this command
1497fails, the current connection remains (if there is any), however if it succeeds
1498then the current connection is closed and the new connection becomes the only
1499active one.
1500
1501All arguments that are accepted by B<\connect> are also accepted by
1502B<\reconnect> (in fact B<\reconnect> uses B<\connect> to establish the new
1503connection).
1504
1505=item \run
1506
1507This command will execute a script file like B<\loop> but the B<\run> command
1508will allow optional script parameters. Furthermore the command accepts the
1509following parameters.
1510
1511=over 4
1512
1513=item -e
1514
1515Run the script file with echo on.
1516
1517=item -f
1518
1519Suppress footers.
1520
1521=item -h
1522
1523Suppress headers.
1524
1525=item -l
1526
1527Suppres separator lines with pretty output style.
1528
1529=item -n
1530
1531Disable SQL buffer variable expansion.
1532
1533=item -p
1534
1535Report runtime statistics.
1536
1537=item -m style
1538
1539Specify output style {bcp|csv|horiz|html|meta|none|pretty|vert}.
1540
1541=item -i filename
1542
1543Required parameter to specify a filename to be run by I<sqsh>.
1544
1545=back
1546
1547For example: B<\run -p -i ~/tmp/runtst.sqsh 10 -m pretty>
1548
1549=item \lcd dirname
1550
1551Local Change Directory. This command takes a directory name as argument and
1552changes the local SQSH context to this directory. You can use B<\lcd -> to
1553return back to the previous directory. If you exit I<sqsh> then the shell is
1554still in the same directory from where sqsh was started.
1555
1556=item \pwd
1557
1558Print Working Directory. Show the name of the current local working directory.
1559
1560=item \ls
1561
1562List files in the current directory. Does not take any arguments and is
1563basically a shortcut for B<\shell ls>.
1564
1565=item \snace
1566
1567Will show the session expiration interval for a network authenticated session,
1568like in a Kerberos enabled session, for example.
1569
1570=item \go [options] [xacts]
1571
1572Sends the contents of the B<Work Buffer> to the database, establishing a new
1573connection to the database if one does not already exist (by calling the
1574B<\connect> above). It them displays the results of the query back to stdout and
1575returns, causing the B<Work Buffer> to be cleared and moved to the end of the
1576B<History Buffer>.
1577
1578If the B<Work Buffer> is empty and the B<$repeat_batch> variable is set to "On",
1579B<\go> will attempt to re-run the last command executed (this will only work in
1580interactive mode if history support is enabled).
1581
1582B<\go> accepts the following arguments:
1583
1584=over 4
1585
1586=item -d display
1587
1588If X11 support is compiled into sqsh, and X display mode is being used (see
1589B<-x>, below), then I<display> will be used as the X display area for the result
1590set. By default the environment variable B<$DISPLAY> is assumed.
1591
1592=item -e
1593
1594Echo the expanded SQL buffer before sending it to the server.
1595
1596=item -f
1597
1598Turns off the display of the footer message "(%d rows affected)". Footer
1599messages may also be turned off via the B<$footers> variable.
1600
1601=item -h
1602
1603Turns off all column headers. These may also be turned off via the B<$headers>
1604variable.
1605
1606=item -m style
1607
1608Temporarily changes the display style to I<style> for the duration of the
1609command. Currently supported styles are B<horiz> (or B<hor> or B<horizontal>),
1610B<vert> (or B<vertical>), B<bcp>, B<csv>, B<html>, B<meta>, B<pretty> and
1611B<none>. The display style may be permanently set via the B<$style> variable or
1612the B<-m> command line flag.
1613
1614=item -l
1615
1616Suppress separator lines when using the B<-m pretty> output style. May also
1617be turned off via the B<$nosepline> variable.
1618
1619=item -n
1620
1621Turns off variable expansion in the B<Work Buffer> prior to sending it to the
1622server, this may also be turned off via the B<$expand> variable.
1623
1624=item -p
1625
1626Turns on output of performance statistics when the result set has been
1627successfully returned from the server. This may also be turned on via the B<-p>
1628command line argument to sqsh, or the B<$statistics> variable.
1629
1630=item -s sec
1631
1632If the value of I<xacts> is greater than 1, this causes sqsh to sleep for I<sec>
1633seconds before executing the next transaction. Note that the time spent sleeping
1634is excluded from the statistical information displayed with the B<-p> flag.
1635
1636=item -t [filter]
1637
1638Filters the command batch through an external program, I<filter>, and prior to
1639being sent to the SQL Server. If I<filter> is not supplied, then B<$filter_prog>
1640is used (default is 'm4 -'). This value may also be set via the B<$filter> and
1641B<$filter_prog> variables.
1642
1643=item -w width
1644
1645Overrides the value of B<$width> for the life of the query (see B<$width>
1646below).
1647
1648=item -x [xgeom]
1649
1650Turns on the X11 display filter (only if X11 support is compiled into sqsh),
1651which causes the result set to be sent to a separate window. If I<xgeom> is
1652supplied, then this value will be used as B<$xgeom> for the life of the query
1653(see B<$xgeom> below).
1654
1655=item -T xwin_title
1656
1657Specify the title name of the X result window to create. This will temporarily
1658override the value of B<$xwin_title>. Only useful to specify -T in conjunction
1659with B<-x>.
1660
1661=item xacts
1662
1663Specifies number of times the contents of the B<Work Buffer> should be executed.
1664Note that, similar to isql, a result set will only be displayed during the final
1665execution of the batch. Also, the contents of the B<Work Buffer> are only
1666expanded once, prior to the first execution, so the contents of the buffer will
1667not change between subsequent executions.
1668
1669=back
1670
1671=item \bcp [bcp_options] table[:slicenumber|:partition name]
1672
1673The B<\bcp> commands acts as a sort of enhanced B<\go> command that redirects
1674the result set(s) of the batch to another server via the bcp protocol. While it
1675is possible to B<\bcp> the result set back to the current server (the
1676B<$DSQUERY> variable), this is achieved more easily via a SELECT INTO.
1677
1678The nitty-gritty details of B<\bcp> go like this: First the current SQL batch is
1679expanded (unless the B<$expand> variable is set to 0) and shipped off to the
1680database for processing. If all goes well, a new connection is established to
1681the destination database (as specified via B<$DSQUERY> or the B<-S> flag) to
1682transfer the result set using bcp. Then, the output of the source database
1683connection is bound to the new bcp connection and data transfer is performed.
1684B<\bcp> can handle multiple result sets without any problem (including result
1685sets returned from stored procedures, etc.) provided that all of the result sets
1686are valid for the destination table.
1687
1688The equivalent of a "bcp out" may be performed using the B<bcp> display style
1689setting and file redirection (see the B<$style> variable).
1690
1691=over 4
1692
1693=item -A packet
1694
1695Specifies the TDS packet size used to communicate with the destination server.
1696If not supplied this defaults to the value the B<$packet_size> variable, or (if
1697that is not set), the default server packet size (usually 512 bytes).
1698
1699=item -b batch_size
1700
1701The number of records transferred in a single transaction between servers. Note
1702that reaching the end of a result causes the batch to be transferred, regardless
1703of the value of I<batch_size>. The default is the entire result set.
1704
1705=item -i "<initialization command>"
1706
1707Using the I<-i> parameter you can send a SQL command to the target server that
1708will be executed just before the bulk copy operation is started. This is useful
1709if you need to truncate the target table first. For example:
1710
1711    1> select * from proddb..materials
1712    2> \bcp -SDTA -i "truncate table testdb..materials" -N -X testdb..materials
1713
1714=item -I ifile
1715
1716The full path of an alternate Sybase I<interfaces> file to use.
1717
1718=item -J charset
1719
1720Specifies the default I<charset> used to communicate with the SQL Server. This
1721defaults to the current character set (the value of the B<$charset> variable).
1722
1723=item -m maxerr
1724
1725The maximum number of batches that may fail before B<\bcp> gives up the ghost
1726(default is 10). Note that this only refers to failures within a given batch.
1727When performing a bcp of multiple result sets to a server, if a given result set
1728has, say, too many columns or bad data types, then the entire bcp process is
1729aborted regardless of the value of I<maxerr>.
1730
1731=item -N
1732
1733Indicates that the value for an identity column in the destination table is
1734being supplied within the result set.
1735
1736=item -P password
1737
1738The I<password> for I<user> required to connect to I<server>. This defaults to
1739B<$password> if not supplied.
1740
1741=item -S server | host:port[:filter]
1742
1743The name or address of the Sybase I<server> to connect, this defaults to
1744B<$DSQUERY> if not supplied.
1745
1746=item -T
1747
1748Transfer the data in transit without performing character set conversion
1749at the client side.
1750
1751=item -U user
1752
1753The Sybase I<user> to connect to the database as, this defaults to B<$username>
1754variable if not supplied.
1755
1756=item -X
1757
1758Causes password negotiation with the destination server to be performed using
1759client-side encryption.
1760
1761=item -z language
1762
1763Specifies the language setting to use.
1764
1765=item table[:slicenumber|:partition name]
1766
1767As with regular B<bcp>, I<table> may be either a fully or partially specified
1768table name in the destination server. Note that since a new database connection
1769is established during the bcp processes that the database context of the
1770connection may not be the same as the current context, so it is usually safest
1771to fully specify the table name in the form database.owner.table.
1772For partitioned tables you may supply a slicenumber or a partition name
1773(separate table name and partition with a colon (:)) to bcp the data into the
1774specified partition.
1775
1776=back
1777
1778=item \rpc [rpc_opt] rpc_name [[parm_opt] [@var=]value ...]
1779
1780The B<\rpc> command is used to directly invoke a stored procedure call in the
1781connected server. This command is particularly useful for communicating with an
1782Open Server that does not directly support language calls.
1783
1784B<\rpc> invokes the remote procedure I<rpc_name> with one or more parameters
1785that may be named (using I<@var>) or anonymous (by not supplying a name).
1786Unfortunately, due to the fact that Sybase's implementation of RPC's, does
1787not directly support most implicit data type conversions (mainly between VARCHAR
1788(the string you supply on the command line) and the most other data types (that
1789the remote procedure is expecting), the syntax for the B<\rpc> command is
1790somewhat complex. However, in short here is how things work:
1791
1792As the B<\rpc> command line is being parsed, I<sqsh> attempts to guess the data
1793type of the parameter I<value> based on the format (for example if it contains
1794only digits, it is assumed to be an integer), I<sqsh> then performs an explicit
1795data type conversion prior to calling the remote procedure call. If I<sqsh>
1796guesses wrong, several flags are supplied to force it to perform the correct
1797data type conversion (see B<parm_opt>).
1798
1799=back
1800
1801=head3 Display Options
1802
1803The following options may be supplied anywhere on the command line and are used
1804to affect the manner in which the result set(s) returning from the remote
1805procedure call are displayed:
1806
1807=over 4
1808
1809=item -d display
1810
1811If X support is compiled into sqsh, the value of I<display> is used as the X
1812windows DISPLAY variable. Note, this is usually supplied with the B<-x> flag,
1813below.
1814
1815=item -f
1816
1817Turns off the display of the footer message "(%d rows affected)". Footer
1818messages may also be turned off via the B<$footers> variable.
1819
1820=item -h
1821
1822Turns off all column headers. These may also be turned off via the B<$headers>
1823variable.
1824
1825=item -m style
1826
1827Temporarily changes the display style to I<style> for the duration of the
1828command. Currently supported styles are B<horiz> (or B<hor> or B<horizontal>),
1829B<vert> (or B<vertical>), B<bcp>, B<csv>, B<html>, B<meta>, B<pretty> and
1830B<none>. The display style may be permanently set via the B<$style> variable or
1831the B<-m> command line flag.
1832
1833=item -r
1834
1835Request to recompile the procedure prior to execution.
1836
1837=item -w width
1838
1839Temporarily sets the output width to I<width>. The output width may be
1840permanently set via the I<$width> variable.
1841
1842=item -x [xgeom]
1843
1844Sends output to a separate X window. If I<xgeom> is supplied, then the X window
1845uses this geometry (see B<$xgeom> for details).
1846
1847=item -T xwin_title
1848
1849Specify the title name of the X result window to create. This will temporarily
1850override the value of B<$xwin_title>. Only useful to specify -T in conjunction
1851with B<-x>.
1852
1853=back
1854
1855=head3 Parameter Options
1856
1857The following options may be supplied immediately prior to specifying a
1858parameter I<value> and are used to affect the way in which I<sqsh> interprets
1859the contents of the I<value> prior to calling the remote procedure. Although
1860I<sqsh> will allow any combination of these parameters to be combined, it only
1861really makes sense to combine the B<-x> flag with any other flag.
1862
1863=over 4
1864
1865=item -b
1866
1867Indicates that the I<value> that is specified should be converted to VARBINARY
1868before calling I<rpc_name>. This flag is implicit (i.e. you need not supply it)
1869if I<value> starts with "0x" and contains only digits.
1870
1871=item -c
1872
1873Indicates that the I<value> that is specified should be converted to VARCHAR
1874prior to calling I<rpc_name>. This flag is implicit if I<value> does not match
1875any of the implicit conversions for the other data types.
1876
1877=item -d
1878
1879Indicates that the I<value> that is specified should be converted to double
1880(float) before calling I<rpc_name>. This flag is implicit if I<value> is in
1881valid floating point notation (e.g. 0.1, .1, 1.4e10, or 4e10).
1882
1883=item -i
1884
1885Indicates that the I<value> that is specified should be converted to integer
1886(int) before calling I<rpc_name>. This flag is implicit if I<value> contains
1887only digits (and, optionally, a leading sign).
1888
1889=item -y
1890
1891Indicates that the I<value> that is specified should be converted to money
1892before calling I<rpc_name>. This flag is implicit if I<value> begins with a "$",
1893and contains only digits and, optionally, a decimal.
1894
1895=item -n
1896
1897Indicates that the I<value> that is specified should be converted to numeric
1898before calling I<rpc_name>. This flag is never implicit, as I<value> would
1899always match either int (B<-i>) or float (B<-d>); however, both of these types
1900will implicitly be converted to a numeric as necessary by the procedure call.
1901
1902=item -u
1903
1904Indicates that I<value> should be ignored and treated as a NULL value, This flag
1905is implicit if I<value> is "".
1906
1907=back
1908
1909=head2 Buffers
1910
1911The following commands may be used to create, destroy, or manipulate the various
1912buffers described in the B<BUFFERS> section, above.
1913
1914=over 4
1915
1916=item \clear
1917
1918The B<\clear> command will discard the current buffer and in contradiction with
1919the B<\reset> command, will not save the current buffer to the history. When
1920sqsh is compiled with readline support, this command will also clear the screen.
1921(as ^l does.) The alias B<clear> is automatically established upon startup.
1922
1923=item \history [-i] [-x count]
1924
1925Displays the last B<$histsize> batches that have either been sent to the
1926database via the B<\go> command or cleared from the B<Work Buffer> via the
1927B<\reset> command. With option B<-i> also display the number of times the buffer
1928is used and the last time the buffer was used. This information may be of
1929special interest when using the B<$histunique> feature. The B<-x> option may
1930specify the number of most recent history entries to display instead of the
1931total list of history entries.
1932
1933=item \hist-load [filename]
1934
1935Load a history file and append items to the current history list.
1936Use B<$history> if no filename is specified as a parameter.
1937
1938=item \hist-save [filename]
1939
1940Will save the current history buffers to the B<$history> file or to the filename
1941specified as a parameter.
1942
1943=item \redraw
1944
1945Returns a request back to the current read-eval-print loop for it to redisplay
1946the current B<Work Buffer>. If run from non-interactive mode, this command has
1947no effect.
1948
1949=item \reset
1950
1951The B<\reset> command corresponds directly to the I<isql> 'reset' command,
1952returning a request to the read-eval-print loop to clear the contents of the
1953current B<Work Buffer> and, if you are running in interactive mode, place a copy
1954of the buffer into the B<History Buffer>. The alias B<reset> is automatically
1955established upon startup of I<sqsh> for backward compatibility with I<isql>.
1956
1957=item \buf-append dst-buffer [src-buffer]
1958
1959Appends the contents of I<src-buffer> (defaults to !.) to the contents of
1960I<dst-buffer>, if it exists. If I<dst-buffer> doesn't exist it is created.
1961
1962=item \buf-copy dst-buffer [src-buffer]
1963
1964Copies the contents of I<src-buffer> (defaults to B<!.>, the B<Work Buffer>, if
1965not supplied), to I<dst-buffer>. Refer to B<BUFFERS> for information on buffer
1966naming conventions.
1967
1968=item \buf-del [buffer|range]
1969
1970Remove a history buffer from the history list. You can also specify a range list
1971consisting of the first and last buffer numbers separated by a '-'. For example:
1972"\buf-del 1-10" will delete the first 10 history entries. Another example,
1973"\buf-del 21" will only delete buffer number 21. Note that the history buffers
1974will be renumbered consecutively.
1975
1976=item \buf-edit [-r read-buf] [-w write-buf]
1977
1978The B<\buf-edit> command is used to edit the contents of a buffer and place the
1979changes into another buffer. This command may only be run while in interactive
1980mode. If I<read-buf> is not supplied then the buffer to be edited defaults to
1981!., if it is not empty, otherwise it defaults to !!. If I<write-buf> is not
1982supplied then the edited buffer is written back to !..
1983
1984By default, B<\buf-edit> uses the environment variable B<$EDITOR> first,
1985followed by B<$VISUAL> to determine which editor to use, defaulting to 'vi'
1986if the variable is not set.
1987
1988It is important to note that as of release 1.2, B<\buf-edit> is no longer able
1989to use the name of an alias to it as the name of the editor to launch. This is
1990primarily due to the change in the behavior of alias (see section B<Aliasing>,
1991below, for details).
1992
1993The commands B<edit vi> and B<emacs> are automatically established upon startup
1994of I<sqsh> for backward compatibility with I<isql>.
1995
1996=item \buf-get buffer
1997
1998The B<\buf-get> command is supplied as a shorthand method of running
1999B<\buf-copy> It is the equivalent of running:
2000
2001    \buf_append !. buffer
2002
2003=item \buf-load [-a] filename [dst-buffer]
2004
2005Copies the contents of I<filename> in I<dst-buffer> (defaults to !.). If the
2006B<-a> flag is supplied, the contents of I<filename> are appended to
2007I<dst-buffer>. Note that it is illegal to attempt to write to the contents of
2008the history buffer.
2009
2010=item \buf-save [-a] filename [src-buffer]
2011
2012Saves the contents of I<src-buffer> (defaults to !.) to I<filename>. If the
2013B<-a> flag is supplied the contents are appended to I<filename> rather than
2014overwriting the current contents.
2015
2016=item \buf-show [buffer]
2017
2018Displays the contents of the named I<buffer>. If I<buffer> is not supplied, then
2019the contents of all named buffers are displayed. This command is slightly
2020different from the commands above in that it is only legal to supply a
2021B<Named Buffer> I<buffer>, B<History Buffers>, and the B<Work Buffer> will have
2022no results.
2023
2024=back
2025
2026=head2 Variables
2027
2028The following command(s) are used to manipulate the contents of internal
2029variables and environment variables.
2030
2031=over 4
2032
2033=item \set [-x] [name=I<value> ...]
2034
2035If no arguments are supplied to B<\set> then the current values of all variables
2036are displayed. Otherwise the variable I<name> is set to I<value>. Note that some
2037internal variables (see B<SPECIAL VARIABLES>) may only be set with certain
2038I<value>s, so this action may fail, leaving the previous contents on I<name>
2039intact. The B<-x> flag causes the variable to be exported to the environment of
2040any programs launched from I<sqsh>.
2041
2042=back
2043
2044=head2 Job Control
2045
2046The following commands are used to view the status of, or manipulate background
2047jobs that are currently running, these correspond roughly to the commands
2048supplied by such shells as B<csh(1)>.
2049
2050=over 4
2051
2052=item \jobs [-i]
2053
2054Displays the status of any currently running jobs, including whether or not
2055these jobs have pending output, how long they have been running, and when they
2056were started. The B<-i> option will show some additional job information. Note
2057that the total run time of the job is determined from the moment the job is
2058marked complete by the read-eval-print loop when polled, not when it actually
2059ended and is flagged as terminated by the signal handler.
2060
2061=item \wait [job_id]
2062
2063Will pause until job designated by I<job_id> completes. If I<job_id> is a
2064negative number then B<\wait> will pause until I<any> pending jobs completes. If
2065there are no jobs pending, or I<job_id> does not belong to a running job, then
2066an error message is displayed. Note that if multiple jobs are running, and a
2067B<\wait> is issued for one of them, the other jobs may not automatically get
2068signaled when completed within the wait period of the specific job. The other
2069jobs may need to get signaled with a B<\wait -1> as well to be noticed complete
2070by I<sqsh>.
2071
2072=item \kill job_id
2073
2074Terminates the job specified by I<job_id>, throwing away any output that may be
2075deferred for the job. If I<job_id> is not a running job then an error message is
2076displayed.
2077
2078=item \show job_id
2079
2080Displays the deferred output of completed background job I<job_id> and removes
2081the job from the list of pending jobs (removing the defer file in the process).
2082If I<job_id> is still running, or is not a valid complete job, then an error
2083message is displayed. You may need to issue a B<\wait job_id> first, to get
2084notified of actual job completion.
2085
2086=back
2087
2088=head2 Aliasing
2089
2090As of release 1.2, I<sqsh> supports full I<csh>-style command aliasing. With
2091this feature, I<sqsh> checks the first word of each line, I<prior to any form of
2092expansion>, to see if it matches the name of an existing alias. If it does, the
2093command is reprocessed with the alias definition replacing its name. Unlike
2094I<csh>, however, only one form of history substitution is available within an
2095alias: the 'B<!*>' entry, indicating the current line being expanded. If no
2096history expansion is called for, the arguments on the command line remain
2097unchanged.
2098
2099Like I<csh>, aliases are not recursively expanded, so it is perfectly legal to
2100create an alias that expands to a command by the same name.
2101
2102The following command is used to create an alias:
2103
2104=over 4
2105
2106=item \alias [alias_name=alias_body]
2107
2108If no arguments are supplied to the B<\alias> command, then the list of aliases
2109currently in effect is displayed. Otherwise, it creates a new alias with a name
2110of I<alias_name> and a body of I<alias_body>; if I<alias_name> already exists,
2111the body of the existing I<alias_name> is replaced with the new definition.
2112
2113After defining the new alias, whenever I<sqsh> encounters a line beginning with
2114I<alias_name>, the remainder of the line is replaced with I<alias_body> before
2115any further processing is performed.
2116
2117If the string 'B<!*>' exists anywhere within I<alias_body>, the arguments
2118supplied to the alias are inserted at that point, otherwise the argument are
2119appended to the end of the alias definition. For example:
2120
2121    1> \alias hi='\echo !* said hello'
2122    1> hi Scott
2123    Scott said hello
2124
2125where as if the alias does not include the B<!*> keyword, then it behaves like
2126so:
2127
2128    1> \alias hi='\echo said hello'
2129    1> hi Scott
2130    said hello Scott
2131
2132It is perfectly legal to include a B<!*> more than once within a given
2133I<alias_body>. Currently there is no way to escape the string B<!*>, if you
2134really need this feature send me mail.
2135
2136=item \unalias alias_name
2137
2138Removes I<alias_name>.
2139
2140=back
2141
2142=head2 Miscellaneous
2143
2144The left over commands.
2145
2146=over 4
2147
2148=item \exit [x]
2149
2150The B<\exit> command requests that current read-eval-print loop cease
2151processing. When the last loop returns, I<sqsh> B<exit(1)>s. You may specify a
2152exit code as parameter which will be stored in B<$exit_value> and will be used
2153as return value to the shell upon exit of I<sqsh>. (0 <= x <= 255).
2154
2155=item \abort
2156
2157Causes all nested read-eval-print loops to abort processing, causing I<sqsh> to
2158exit with an exit value of 254 (see section B<EXIT STATUS>).
2159
2160=item \read [-a] [-n] [-h] var_name [< filename]
2161
2162Reads a line of input from the user, placing the text of the line in the
2163variable I<var_name>. If the B<-n> is used, then the trailing new-line is left
2164on the line of text, and if B<-a> is supplied, then the text of the line is
2165appended to the existing value of I<var_name>. The B<-h> flag turns off echoing
2166of typed characters back to the user. It is also possible to read the contents
2167of a file using the I<\<> file redirection notation.
2168
2169=item \sleep seconds
2170
2171Causes I<sqsh> too pause for I<seconds>. This is useful within scripts of
2172batches which need to pause briefly between batches (it was primarily useful to
2173me for testing background jobs).
2174
2175=item \echo [-n] [args ...]
2176
2177Just like the UNIX B<echo(1)>, this prints its arguments to stdout, followed by
2178a new-line. If the B<-n> flag is supplied, the newline is omitted.
2179
2180=item \warranty
2181
2182Displays the standard GNU warranty.
2183
2184=item \help [command]
2185
2186Without any arguments B<\help> displays a brief list of all available commands,
2187otherwise, it provides specific help for I<command>, if available. When help is
2188requested on a specific I<command>, B<\help> looks for the file
2189I<$help_dir/command.hlp> and displays it to stdout.
2190
2191=item \shell [shell command]
2192
2193If I<shell command> is not supplied then I<sqsh> executes B<$SHELL>. If the
2194B<$SHELL> variable has not been set, then, by default, /bin/sh is executed.
2195Otherwise, if I<shell command> is supplied then it is executed. The exit status
2196of the command executed is stored in the special B<$?> read-only environment
2197variable.
2198
2199=item \lock
2200
2201Locks the current session until the correct password is typed. By default
2202B<\lock> attempts to use the UNIX password (from /etc/passwd or /etc/shadow)
2203associated with the user running I<sqsh> (if sqsh is linked with the crypt
2204library), however if the B<$lock> variable is set then the contents of that is
2205used for validation instead.
2206
2207=back
2208
2209=head2 Aliases
2210
2211The following aliases are established upon startup of I<sqsh>, and are provided
2212primarily for backward compatibility with I<isql>. These may be removed at any
2213time using the B<\unalias> command (either at the prompt, or within your .sqshrc
2214file).
2215
2216=over 4
2217
2218=item !
2219
2220The B<!> alias is provided as a B<csh(1)>-like history mechanism, and is an
2221alias of B<\buf-append>. With release 0.7, this alias is provided only for
2222backwards compatibility with previous releases of I<sqsh>. See B<SPECIAL
2223VARIABLES>, B<$history_shorthand> for details on the new shorthand mechanism
2224(the new shorthand more closely resembles that of B<csh>).
2225
2226=item clear
2227
2228An alias for the B<\clear> command, which causes the contents of the current
2229work buffer to be cleared and discarded. Also the screen will be cleared if
2230readline is compiled into I<sqsh>.
2231
2232=item reset
2233
2234An alias for the B<\reset> command, which causes the contents of the current
2235work buffer to be cleared and copied to history (if in interactive mode).
2236
2237=item exit [x]
2238
2239=item quit [x]
2240
2241An alias for the B<\exit [x]> command, causes the current read-eval-print loop to
2242complete.
2243
2244=item edit
2245
2246=item vi
2247
2248=item emacs
2249
2250These are provided as aliases for the B<\buf-edit> command. See
2251B<COMMANDS-Buffers> for information on the interactions between B<\buf-edit> and
2252aliases.
2253
2254=item go
2255
2256Provided as an alias for the B<\go> command (for obvious reasons).
2257
2258=item help
2259
2260An alias for the B<\help> command.
2261
2262=back
2263
2264=head3 In-Line \go
2265
2266If the variable B<$semicolon_hack> is set to 1 (on), then sqsh supports what is
2267called an in-line B<\go> feature. This allows the current command batch to be
2268terminated and sent to the database in a single step by appending a ';' onto
2269the end of the current work buffer. This allows
2270
2271    1> sp_who;
2272
2273To behave in the same manner as if you had typed:
2274
2275    1> sp_who
2276    2> \go
2277
2278Likewise, anything following the semicolon is passed to the B<\go> command just
2279as if it was run as a normal command:
2280
2281    1> sp_who ; 2>/dev/null | more
2282
2283Unlike most other I<isql> replacements, I<sqsh> attempts to be smart about the
2284semicolons. If a semicolon is contained within a set of single or double quotes
2285it will not be interpreted. This includes multiple quotes. For example:
2286
2287    1> select "This is a multiple line
2288    2> quote; it is smart!" ;
2289
2290In the above example, only the second semicolon (the one at the end of the line)
2291will be interpreted.
2292The variable B<$semicolon_cmd> is a string that contains the command that will
2293be substituted by the semicolon which is B<\go> by default. But you can change
2294that to B<\bcp> for example and execute:
2295
2296    1> select * from pubs2..titles; -S... tempdb..titles
2297
2298In sqsh-2.2.0 you can also set variable B<$semicolon_hack2> to allow multiple
2299commands on one line to be fired by a semicolon. If this option is set you
2300cannot use the construct above to pass additional parameters to the B<\go>
2301command. But of course you can change B<$semicolon_cmd> to your needs as this
2302command will be used to execute SQL batches.
2303
2304    echo "exec sp_who;exec sp_helpdb;\echo Done;" | sqsh -S... -U... -P...
2305
2306In this example the semicolon acts as a B<\go> command to a SQL buffer and as
2307a command separator for sqsh commands that will be executed in sequence.
2308Note that B<$semicolon_hack2> takes precedence over B<$semicolon_hack>.
2309
2310=head1 SPECIAL VARIABLES
2311
2312There are several options that are configurable via the command line options to
2313I<sqsh>, however these are by no means complete. There are many aspects of
2314I<sqsh>'s behavior that may only be modified by setting special variables. (In
2315fact, the command line options really only set these variables for you).
2316
2317=head2 Variable Data types
2318
2319Next to all of the variables that follow is the type of data with which they may
2320be set. Any attempts to set the variable with a type of data that it does not
2321accept will fail.
2322
2323=over 4
2324
2325=item string
2326
2327Any sequence characters.
2328
2329=item boolean
2330
2331A positive I<boolean> value may be represented as either "True", "Yes", "1", or
2332"On" (case insensitive) and a negative boolean value may be represented as
2333"False", "No", "0", or "Off" (case insensitive). However, internally the value
2334of the variable will always be represented as either a "1" or "0".
2335
2336=item path
2337
2338Must be the I<path> name that is readable by the I<sqsh> program.
2339
2340=item int
2341
2342Must be one or more digits. Note that some variables also restrict the range of
2343the integer.
2344
2345=item date-spec
2346
2347This is a string of the format used to specify dates and times for the
2348B<date(1)> command, or the B<strftime(3C)> and B<cftime(3C)> standard C library
2349functions. For example '%H:%M:%S' specifies a time of hours in 24 hour
2350format, followed by a colon, followed by minutes, followed by a colon, followed
2351by seconds.
2352
2353=item float-format
2354
2355A string of the format B<p.s>, where B<p> is the total precision of a floating
2356point value (the total number of digits to be displayed, including those
2357following the decimal) and B<s> is the scale of the value (the total number of
2358digits following the decimal to be displayed).
2359
2360=back
2361
2362=head3 Variables
2363
2364The following variables have special meanings within I<sqsh> and the setting of
2365these variables alter the behavior of the shell.
2366
2367=over 4
2368
2369=item $? (int)
2370
2371This read-only variable may contain the following return value:
2372
2373=over 4
2374
2375=item *
2376
2377The most recent error number returned from the SQL Server (@@errno) of severity
2378> 10 (above informational messages).
2379
2380=item *
2381
2382The exit value of a previously executed pipe command.
2383
2384=item *
2385
2386The return value of the most recently executed sqsh function.
2387
2388=item *
2389
2390The result of the last executed \if statement:
2391
2392=over 4
2393
2394=item 0 - The test evaluated to True.
2395
2396=item 1 - The test evaluated to False.
2397
2398=item 2 - There was an error in the test specification.
2399
2400=back
2401
2402=back
2403
2404=item $# (int)
2405
2406Contains the number of arguments passed into the sqsh function or script.
2407
2408=item $* (string list)
2409
2410Expands to the complete list of arguments supplied to the function or script
2411when invoked.
2412
2413=item ${0}...${N} (int)
2414
2415Used to reference positional function arguments. Argument ${0} is the name of
2416the function being called, ${1} is the first argument, etc.
2417
2418=item $$
2419
2420Expands to the process ID of the current running sqsh session.
2421
2422=item DISPLAY
2423
2424May contain the name of the DISPLAY the X-server uses to put the XWindows
2425result window when using B<\go -x>. Defaults to the I<$DISPLAY> shell
2426environment.
2427
2428=item appname
2429
2430Contains the name I<sqsh> uses to identity itself to the server. Defaults to
2431sqsh-2.1.7. The application name can be retrieved from the sysprocesses table
2432like:
2433    select program_name from master.dbo.sysprocesses where spid=@@pid;
2434
2435=item autouse (string)
2436
2437Note: the meaning of this variable has been deprecated.
2438
2439If B<$autouse> is set, and the B<$database> variable has not been set, then this
2440variable causes B<\connect> to perform a "use B<$autouse>" once a connection has
2441been established.
2442
2443This variable may also be set using the B<-D> command line option.
2444
2445=item banner (boolean)
2446
2447Turns off the banner message displayed on startup, this variable defaults to 1
2448and may also be turned off using the B<-b> command line argument.
2449
2450=item batch_failcount (int)
2451
2452This internal variable is used to keep track of the number of batches that have
2453failed to execute (essentially, the number of times that the error handler was
2454called).
2455
2456A batch is considered failed whenever an error of severity B<$thresh_fail> is
2457encountered. When B<$batch_failcount> reaches B<$thresh_exit> I<sqsh> exits with
2458an exit value of the total number of batches that have failed. Setting
2459B<$batch_failcount> to the string "" will cause it to reset to zero, any other
2460value may have unpredictable results.
2461
2462See B<EXIT STATUS> for details.
2463
2464=item batch_pause (boolean)
2465
2466Causes a "Paused. Hit enter to continue..." message to be displayed after each
2467batch is executed. This variable, in conjunction with B<$echo> is good for
2468debugging SQL scripts specified with the B<-i> option.
2469
2470=item bcp_colsep (string)
2471
2472Used as a separator between columns during BCP style output (see the B<$style>
2473configuration variable and the B<-m> option to the B<\go> command). The default
2474setting is "|".
2475
2476=item bcp_rowsep (string)
2477
2478Used as a separator between rows during BCP style output (see the B<$style>
2479configuration variable and the B<-m> option to the B<\go> command). Note that, a
2480newline ("\n") is automatically appended and should not be supplied.
2481The default setting is "|".
2482
2483=item bcp_trim (boolean)
2484
2485Controls whether or not BCP style output trims trailing spaces from fixed length
2486columns. The default is "True".
2487
2488=item builddate (none)
2489
2490Read only variable specifying the date when the I<sqsh> executable was compiled.
2491
2492=item buildtime (none)
2493
2494Read only variable specifying the time when the I<sqsh> executable was compiled.
2495
2496=item chained (boolean)
2497
2498If set then sqsh uses the "chained" transaction mode (aka "AutoCommit off").
2499Setting this has NO effect on the current connection. It can be set via the
2500command line argument B<-n>.
2501
2502=item charset (string)
2503
2504If this variable is set prior to establishing a connection with SQL Server, then
2505during the connection I<sqsh> will request that the server transform to and from
2506the requested I<charset>. After establishing a connection, this variable is
2507automatically set to the current character set in use.
2508
2509=item clear_on_fail (boolean)
2510
2511Normally, whenever the B<\go> command is run, I<sqsh> clears the current work
2512buffer of its contents, moving them to history. Setting B<$clear_on_fail> to 0,
2513leaves the current work buffer intact if a failure is encountered while sending
2514the contents to the database. The default value is 1, or on.
2515
2516=item colsep (string)
2517
2518Causes the string I<colsep> to be used to delimit SQL column output columns,
2519this defaults to " ", it may also be set via the command line argument B<-s>.
2520
2521=item colwidth (int)
2522
2523Used to control the maximum column width displayed by the B<pretty> display
2524style (see B<$style> below). If a row of a column exceeds this width, it will be
2525wrapped in a relatively visually appealing manner at B<$colwidth> characters.
2526Note, however, that if there is enough screen width to hold all columns
2527B<$colwidth> may be exceeded until the width of the screen is reached.
2528
2529=item database (string)
2530
2531If this variable is set prior to establishing a connection to the SQL Server,
2532the a "use B<$database>" is performed immediately after the connection is
2533established. Once a connection has been established this variable will
2534automatically be set to the current database context.
2535
2536=item date (date-spec)
2537
2538This variable may be set with a date format (see the man page for B<date(1)>),
2539and the variable expands to the current date in the supplied format. The default
2540format for this variable is %d-%b-%y (e.g. 02-Feb-1996).
2541
2542=item datefmt (date-spec)
2543
2544This variable may be set with a date format similar to B<$date> and
2545is used to control the display format of all SQL Server DATE columns. (Similar
2546to B<$datetime>.) Note that only 63 bytes are available in total for the
2547expanded string and the remainder will be truncated.
2548
2549=item datetime (date-spec)
2550
2551This variable may be set with a date format similar to B<$date> and B<$time> and
2552is used to control the display format of all SQL Server DATETIME, BIGDATETIME
2553and SMALLDATETIME columns. Note that only 63 bytes are available in total for
2554the expanded string and the remainder will be truncated.
2555
2556Note that this features relies upon the operating system specific locale
2557information and the setting of B<$localeconv> for determining such things as the
2558name of the month and day, rather than going through the CT-Lib locale
2559information. This means that the date format could potentially miss-match the
2560locale as requested using the B<-z> flag. For example, if I<sqsh> is run on an
2561operating system configured for US English, but requests French as the language
2562of choice using B<-z>, the use of B<$datetime> will cause all date information
2563to be displayed in US English rather than French.
2564
2565Ordinary characters defined in the variable are left in place without any
2566conversion. Characters introduced by a '%' character are replaced during
2567display of a column value according to the definitions in the B<strftime>
2568manual page.
2569
2570=over 4
2571
2572=item []
2573
2574Any contained between a pair of braces ('[' and ']') will be removed
2575when displaying SMALLDATETIME columns. This feature is particularly useful for
2576removing the seconds, milliseconds or microseconds values which are not
2577applicable to SMALLDATETIME anyway. For DATETIME or BIGDATETIME columns,
2578only the actual braces will be removed.
2579
2580=item %q
2581
2582Specifies the milliseconds for DATETIME and TIME and microseconds for
2583BIGDATETIME and BIGTIME data types. In previous versions of sqsh the I<%u>
2584specifier was used for the millisecond part of the datetime datatype.
2585However, as I<%u> is used by B<strftime> to denote the day number of the week,
2586this is replaced by I<%q> since sqsh-2.3. For example when using the default C
2587locale:
2588
2589    1> \set datetime='%e %b %Y %H:%M[:%S.%q]%p'
2590    1> select convert(bigdatetime,getdate())
2591    2> select convert(smalldatetime,getdate())
2592    3> go
2593
2594    -----------------------------
2595    22 Jul 2013 13:26:52.938000PM
2596    -------------------
2597    22 Jul 2013 13:27PM
2598
2599=back
2600
2601=item debug (string)
2602
2603If I<sqsh> has been compiled with debugging enabled (-DDEBUG), this variable may
2604be used to control the amount of debugging output displayed. B<$debug> may be
2605set to a pipe (|) delimited (logical OR) set of the following words to turn on
2606various pieces of debugging: B<ALIAS>, B<AVL>, B<BCP>, B<DISPLAY>, B<ENV>,
2607B<ERROR>, B<EXPAND>, B<FD>, B<HISTORY> (abbr. B<HIST>), B<JOB>,
2608B<READLINE> (abbr. B<RL>), B<RPC>, B<SCREEN>, B<SIG>, B<SIGCHLD> (or B<SIGCLD>),
2609B<TDS> or B<ALL>. Can also be set through the I<-l> startup option.
2610
2611=item debug_tds_capture (string)
2612
2613When B<TDS> debugging is enabled and this variable is defined with a valid file
2614name, a debugging trace will be logged into this file that can be analyzed with
2615Ribo. You might need the devlib versions of the OpenClient library to link with
2616sqsh to be able to use this option. See for more information the ct_debug
2617function in the Sybase SDK documentation.
2618
2619=item debug_tds_logdata (string)
2620
2621When B<TDS> debugging is enabled and this variable is defined with a valid
2622filename, a debugging log will be written by OpenClient with all possible
2623debugging info (CS_DBG_ALL). See also option above.
2624
2625=item defer_bg (boolean)
2626
2627Normally, when a job is run in the background (via a '&' on the command
2628line), the output of the job is deferred to a temporary file (located in
2629I<$tmp_dir>) until the user requests the output to be displayed using B<\show
2630jobid>. This way the results of the job will not interfere with what the user is
2631doing. Setting this variable to false will result in no deferred output files
2632being created and output sent to the screen immediately
2633
2634=item echo (boolean)
2635
2636Setting B<$echo> to on (1) causes each command submitted to the database via the
2637B<\go> command to be displayed prior to the output. This variable defaults to 0
2638(or off), and may also be set using the B<-e> command line option.
2639
2640=item encryption (boolean)
2641
2642Setting the B<$encryption> variable prior to establishing a connection to the
2643server will cause the login connection to be initiated using client-side
2644password encryption. This variable may also be set using the B<-X> command line
2645option. Client-side password encryption will also occur when using the B<-X>
2646option on the B<\connect>, B<\reconnect> or B<\bcp> commands.
2647Please note that the Sybase ASE setting for the B<net password encryption reqd>
2648(15.0.2) configuration parameter may enforce you to use client side password
2649encryption. I<sqsh-2.1.9> supports RSA password encryption when the CT-Lib
2650version in use supports it. RSA password encryption is required if the above
2651mentioned ASE configuration parameter is set to B<2>. Older version of sqsh only
2652supports a value of B<1> (CT-Lib internal encryption algorithms).
2653
2654=item exit_failcount (boolean)
2655
2656Settings this value to 1 causes I<sqsh> to return an exit status of
2657B<$batch_failcount> rather than 0, upon a non-error termination. See B<EXIT
2658STATUS> for details. The default value is 0.
2659
2660=item exit_value (int)
2661
2662When you exit sqsh by specifying an exit code, like B<\exit 3> or using one of
2663the aliases B<exit> or B<quit> commands, then this value is assigned to the
2664B<$exit_value> variable. You can also assign a value using the B<\set> command.
2665When sqsh determines this variable has a non-zero value during termination, this
2666value will be used as exit code. See B<EXIT STATUS> for details.
2667
2668=item expand (boolean)
2669
2670By default when the B<\go> command is executed, the contents of the current work
2671buffer is expanded of all environment variables prior to being sent to the
2672database for execution. By setting this variable to "0", the buffer will no
2673longer be expanded before being sent to the database. This is useful when you
2674either (1) have strings in the buffer that contain a '$' and you don't
2675want them to be expanded, or (2) for performance reasons; it takes time (and an
2676extra copy of the buffer) to perform the variable expansion.
2677
2678=item filter (boolean)
2679
2680Toggles filtering of the SQL batch through an external program (defined by the
2681B<$filter_prog> variable, below) prior to being sent to the SQL Server. Default
2682is '0', or 'off'.
2683
2684=item filter_prog (string)
2685
2686Defines the external program through which the SQL batch will be filtered prior
2687to being sent to the SQL Server. This variable is ignored if B<$filter> is set
2688to '0' or 'off'. The default is 'm4 -'.
2689
2690=item float (float-format)
2691
2692Defines the display format (the precision and scale) for all floating point
2693values displayed by sqsh. The default is '18.6'. Note that values exceeding
2694the defined precision are not truncated, so setting this value too low may cause
2695columns in a result set to be miss-aligned.
2696
2697=item footers (boolean)
2698
2699Toggles the "(%d rows affected)" following a result set. The default for this
2700variable is '1'.
2701
2702=item headers (boolean)
2703
2704Toggles the column headers preceding a result set. The default for this variable
2705is '1'.
2706
2707=item help_dir (path)
2708
2709This is the location of the help files used by the B<\help> command, typically
2710it defaults to something like /usr/local/lib/sqsh/help.
2711
2712=item hist_auto_save (int)
2713
2714When variable B<$histsave> is on and the B<$hist_auto_save> variable has a value
2715greater than 0, then the history will be automatically saved to B<$history>
2716after B<$hist_auto_save> modifications of the history buffers. When the value is
27170 (default), then no automatic history save will be performed.
2718
2719=item histmerge (boolean)
2720
2721When this option is on, sqsh will merge the contents of the history on disk
2722with the history in memory before writing the history back to disk. This is
2723to prevent data loss in the history file when other sqsh sessions have also
2724written to the same history file on disk. This option is off by default which
2725will just overwrite the existing history file when you exit sqsh or the
2726history is being automatically saved because of B<$hist_auto_save> being set.
2727
2728=item histnum (int)
2729
2730Contains the history number that will be assigned to the current command batch
2731as soon as the B<\go> command is executed. This variable should be considered
2732read-only. See also the discussion on the B<$histunique> variable.
2733
2734=item history (path)
2735
2736This is the location of the history file used to store and retrieve a user's
2737history during start-up and shutdown. This defaults to I<$HOME/.sqsh_history>.
2738This variable is expanded each time it is referenced by sqsh, much in the same
2739way that B<$prompt> is referenced each time the prompt is displayed.
2740
2741=item history_shorthand (boolean)
2742
2743This variable is only meaningful within an interactive session. If set, it turns
2744on the ability to append any named buffer or history buffer onto the current
2745work buffer in a 'sh' history style, such as '!40'. Be careful with this
2746feature, I<sqsh> is not terribly intelligent with looking for history shorthand,
2747so it is possible that it may get confused (although, it is smart enough to
2748ignore !'s in quoted strings).
2749
2750=item histsave (boolean)
2751
2752The value of this variable is used by I<sqsh> to indicate whether the history
2753should be saved to B<$history> prior to termination of sqsh.
2754
2755=item histsize (int)
2756
2757The value of this variable is used to alter the maximum number of history
2758entries are maintained by I<sqsh> (the default is 10). Note that decreasing the
2759value of this variable causes some history entries to be lost.
2760
2761=item histunique (boolean)
2762
2763If set, I<sqsh> maintains a MRU-LRU order of executed buffers and does not store
2764duplicate command buffers. For example, observe the following situation:
2765
2766    LINUX1502.user1.master.1> \history
2767    (1) sp_who
2768    (2) grant role mon_role to sa_role
2769    (3) select * from monProcessActivity
2770    (4) select @@authmech,show_sec_services()
2771    (5) select @@servername,@@authmech,show_sec_services()
2772    LINUX1502.user1.master.1> sp_who
2773    LINUX1502.user1.master.2> go
2774    ... output omitted
2775    LINUX1502.user1.master.1> \history
2776    (1) grant role mon_role to sa_role
2777    (2) select * from monProcessActivity
2778    (3) select @@authmech,show_sec_services()
2779    (4) select @@servername,@@authmech,show_sec_services()
2780    (5) sp_who
2781
2782I<sp_who> is the last executed command and the buffer - originally the last in
2783the list - is now on top of the list. When an already existing buffer is reused,
2784the value of the B<$histnum> variable is not changed.
2785
2786=item hostname (string)
2787
2788Used during the connection process to indicate to SQL Server the name of the
2789host from which I<sqsh> is connecting. This variable may also be set using the
2790B<-H> flag.
2791
2792=item ifs (string)
2793
2794The list of Internal Field Separators.
2795
2796=item ignoreeof (boolean)
2797
2798By default, I<sqsh> terminates if the user presses ^d (control-D) on an empty
2799line and readline support is compiled in. If B<$ignoreeof> is set in the sqshrc
2800file you get a warning message instead:
2801
2802    CTRL-D: Use "exit" or "quit" to leave the sqsh shell.
2803
2804This is equivalent to using "set -o ignoreeof" in the bash shell.
2805
2806=item interactive (boolean)
2807
2808This is a variable used internally and should probably not be altered by the
2809user. If B<$interactive> is '0', then the prompt is not displayed, the
2810history is neither read nor written and some user messages are suppressed.
2811
2812=item interfaces (path)
2813
2814This is the full path name of the interfaces file, it defaults to
2815I<$SYBASE/interfaces>.
2816
2817=item keytab_file (string)
2818
2819Used in Kerberos and DCE user authentication security mechanisms. Corresponds
2820with the B<-K> startup option.
2821
2822See also the discussion on Kerberos Support.
2823
2824=item keyword_completion (int/string)
2825
2826This variable only applies if GNU Readline support has been compiled into
2827I<sqsh>. B<$keyword_completion> is used to control the T-SQL keyword completion
2828feature in readline, and may be set using either an integer between 0 and 4, or
2829one of the strings I<none>, I<lower>, I<upper>, I<smart>, or I<exact>. If it is
2830set to either 0 or I<none>, then no keyword completion is performed (this is the
2831default). I<lower> or 1, causes I<sqsh> to complete the keyword in lowercase,
2832regardless of the case that the partially completed keyword was typed. I<upper>
2833or 2 forces completion to be performed in upper case, I<smart>, or 3, bases the
2834decision on case upon the first character of the partial keyword, and I<exact>
2835completes the keyword in exactly the same case as defined in the I<.sqsh_words>
2836(for the built-in T-SQL keywords, this will be lower case).
2837New in I<sqsh-2.5> is that when regular Readline completion does not match
2838the typed string with a keyword, then filename completion will be tried in the
2839current directory. For example:
2840
2841    SYBASE.sa.master.1> \lcd $SYBASE/$SYBASE_ASE/scripts
2842    \lcd: local directory changed to: /opt/sybase/ASE-15_0/scripts
2843    SYBASE.sa.master.1> \run -n -i ./instm<TAB>
2844
2845results in the completed filename "./instmsgs.ebf".
2846
2847=item keyword_dynamic (boolean)
2848
2849This variable controls the dynamic loading of keywords in the completion list
2850when initially logging in to the server or when the database context is changed
2851using the I<use database> command. When this variable is set to 'On'
2852(default is 'Off'), then the query that is provided through the
2853B<$keyword_query> variable is executed and the query result set is loaded into
2854the Readline completion list. This will only work for Sybase ASE and Microsoft
2855SQL servers.
2856This variable also controls dynamic loading of a column list to be auto-
2857completed by Readline. When an object name is followed by a dot and TAB
2858completion is requested, I<sqsh> dynamically creates a list of columns that
2859belongs to the object (table, view, procedure) and allows for Readline TAB
2860completion of the column or parameter names. This feature is only available if
2861GNU Readline support has been compiled into I<sqsh> and B<$keyword_completion>
2862is set to a value greater than zero. In sqsh-2.4 it is also possible to use
2863the object alias in the SQL buffer for auto-completion. For example when you
2864enter the following query in the buffer and type the TAB key twice after
2865the alias 'd' and the dot, a list of column names will be produced for the
2866'sysdatabases' table for further completion:
2867
2868    SYBPROD.sa.tempdb.1> select * from master..sysdatabases d,
2869    SYBPROD.sa.tempdb.2>               master.dbo.sysusages u
2870    SYBPROD.sa.tempdb.3> where d.<TAB><TAB>
2871    d.audflags         d.def_remote_loc   d.durability       d.status2
2872    d.audflags2        d.def_remote_type  d.logptr           d.status3
2873    d.crdate           d.deftabaud        d.name             d.status4
2874    d.dbid             d.defvwaud         d.spare            d.suid
2875    d.defpraud         d.dumptrdate       d.status           d.version
2876    SYBPROD.sa.tempdb.3> where d.
2877
2878This works both for the T-SQL join syntax and the ANSI inner, outer, left and
2879right join syntax. Note that sqsh is now able to perform cross database
2880auto-completion as well.
2881
2882=item keyword_file (string)
2883
2884If Readline support has been compiled into I<sqsh>, and I<sqsh> is being run in
2885interactive mode, the contents of this file are used for keyword tab completion
2886by Readline rather than the default set of T-SQL syntactical keywords. The
2887default is I<$HOME/.sqsh_words>. When B<$keyword_dynamic> is enabled this
2888takes precedence and overrules the list loaded from B<$keyword_file>.
2889
2890=item keyword_query (string)
2891
2892This variable contains the query that will be executed when a change of database
2893is detected or during initial login (Msg 5701). The default query is:
2894
2895    select name from sysobjects order by name
2896
2897But you can supply a different query that suits your needs even better. E.g.
2898
2899    \set keyword_query="\\
2900      select name from sysobjects \\
2901      where type in ('U','V','P','S') \\
2902      union \\
2903      select name from sybsystemprocs..sysobjects \\
2904      where type='P' \\
2905      order by name"
2906
2907This feature is controlled by the variables B<$keyword_completion> and
2908B<$keyword_dynamic> and is only available if GNU Readline support has been
2909compiled into I<sqsh>.
2910
2911=item language (string)
2912
2913The B<$language> variable is used while establishing a connection to the server
2914to specify the national language used to display system prompts and messages.
2915The variable will automatically track the current language setting of the
2916server. This may also be set via the B<-z> flag.
2917
2918=item lineno (int)
2919
2920This is an internal variable and should not be altered by the user. It is used
2921to maintain the line number that is being typed into within the current work
2922buffer.
2923
2924=item linesep (string)
2925
2926Used to configure the line separator for the horizontal display style, this
2927defaults to "\n\t".
2928
2929=item localeconv (boolean)
2930
2931A boolean variable that when set to true will result in the Operating System
2932locale to be used for displaying all datetime (DATETIME, SMALLDATETIME, TIME,
2933DATE, BIGDATETIME and BIGTIME) and the numeric, decimal, real, float and
2934money/smallmoney datatypes in the result set. When this variable is
2935set to false (i.e. the default), sqsh will use the internal C/POSIX locale
2936to determine how to display these datatypes. For example:
2937
2938    ~$ export LANG=nl_NL.utf8
2939    ~$ locale -ck LC_TIME
2940    LC_TIME
2941    abday="zo;ma;di;wo;do;vr;za"
2942    day="zondag;maandag;dinsdag;woensdag;donderdag;vrijdag;zaterdag"
2943    abmon="jan;feb;mrt;apr;mei;jun;jul;aug;sep;okt;nov;dec"
2944    mon="januari;februari;maart;april;mei;juni;juli;augustus;september;oktober;
2945         november;december"
2946    am_pm=";"
2947    ...
2948
2949    ~$ sqsh -Llocaleconv=On -Ldatetime="%A %e %B %Y" -C"select getdate()"
2950     ---------------------------
2951            maandag 22 juli 2013
2952
2953    (1 row affected)
2954    ~$ sqsh -Llocaleconv=Off -Ldatetime="%A %e %B %Y" -C"select getdate()"
2955     ---------------------------
2956             Monday 22 July 2013
2957
2958    (1 row affected)
2959
2960Also, depending on the locale, the decimal specifier in money, numeric,
2961decimal, float and real datatypes may be displayed as a B<",">. Note that sqsh
2962does not take the thousands_sep into account when displaying numerical data
2963values.
2964
2965=item lock (string/write-only)
2966
2967Defines the password to be used by the B<\lock> command. If unset or set to the
2968string "NULL", then the UNIX password of the user running I<sqsh> is used
2969instead (if possible). Note that B<$lock> will always expand to the string
2970"*lock*" if referenced.
2971
2972=item login_timeout (int)
2973
2974The number of seconds to wait when attempting to create a new connection to a
2975data server. Default is 0 (infinite wait). See also the B<-T> command line
2976option.
2977
2978=item max_timeout (int)
2979
2980Controls the number of times a query needs to reach its time-out value before
2981the session is aborted. See B<$query_timeout> and the B<-Q> command line flag.
2982The following messages will be displayed and sqsh exits with value 255 when the
2983B<$max_timeout> limit is reached.
2984
2985    Query or command timeout detected, session aborted
2986    The client connection has detected this x time(s)
2987    Aborting on max_timeout limit
2988
2989=item maxlen (int)
2990
2991Controls the maximum amount of data that will be displayed (in any display mode)
2992in a single column. This setting will automatically truncate the output of
2993particularly large data types (such as TEXT) to the value supplied. The default
2994setting is 32768 bytes (32KB).
2995
2996=item newline_go (boolean)
2997
2998This flag is used as a horrible kludge to support an "empty" alias for the
2999B<\go> command, that is, the equivalent of supplying "-c ''" or just "-c" on
3000the command line. When on, an empty line is interpreted as a call to the B<\go>
3001command. This feature is not recommended but is supplied for completeness.
3002
3003=item nosepline (boolean)
3004
3005Suppress the separator lines with the pretty output style.
3006
3007=item output_parms (boolean)
3008
3009Flag used to enable or disable the display of output parameter result sets from
3010stored procedures. The default is to enable the display.
3011
3012=item p2faxm (int)
3013
3014Implements the feature Print messages to File (P2F). This variable is used in
3015conjuction with B<$p2fname> and specifies a threshold on the number of messages
3016per batch that will be send to the terminal window. If the threshold is
3017exceeded, the remaining messages will be send to the specified file. The default
3018value is NULL which disables the P2F feature. Also an assigned value of 0
3019disables this feature. This feature will only work in interactive mode and is to
3020prevent an accidental flood of server messages scrolling over the screen.
3021For example:
3022
3023    SYBASE.sa.tempdb.1> \set p2fname=/tmp/sqsh_p2f.out
3024    SYBASE.sa.tempdb.1> \set p2faxm=10
3025    SYBASE.sa.tempdb.1> create clustered index keys_cx on keys(id)
3026    SYBASE.sa.tempdb.2>   with ignore_dup_row
3027    SYBASE.sa.tempdb.2> go
3028    Warning: deleted duplicate row.  Primary key is '0'
3029    Warning: deleted duplicate row.  Primary key is '1'
3030    Warning: deleted duplicate row.  Primary key is '2'
3031    Warning: deleted duplicate row.  Primary key is '3'
3032    Warning: deleted duplicate row.  Primary key is '4'
3033    Warning: deleted duplicate row.  Primary key is '5'
3034    Warning: deleted duplicate row.  Primary key is '6'
3035    Warning: deleted duplicate row.  Primary key is '7'
3036    Warning: deleted duplicate row.  Primary key is '8'
3037    Warning: deleted duplicate row.  Primary key is '9'
3038    Warning: Number of printed server messages exceeds p2faxm=10 limit for current batch.
3039             Remaining server messages will be printed to file: /tmp/sqsh_p2f.out
3040
3041=item p2fname (path)
3042
3043Contains the filename for the Print messages to File (P2F) feature described
3044above. Default is NULL which disables the P2F feature. If a file is specified
3045that already exists, then new data will be appended.
3046
3047=item packet_size (int)
3048
3049Defines the size of the TDS packets used to communicate with SQL. Changing the
3050value of the variable will not affect the current connection but will take
3051effect upon the next B<\reconnect> command. Specifying a value of NULL indicates
3052that the default packet size is desired.
3053
3054=item password (string/write-only)
3055
3056This is the user's current password. A NULL password may be assigned using an
3057explicit "NULL" string. For security reasons, when referenced the B<$password>
3058variable will always expand to the string "*password*".
3059
3060=item password_retry (boolean)
3061
3062When the variable is on and sqsh started in interactive mode, sqsh will ask for
3063the password again if login failed. When set to 'off', sqsh will terminate
3064immediately. Default is on.
3065
3066=item principal (string)
3067
3068Used in Kerberos user authentication as the Server principal name when it
3069differs from the B<$DSQUERY> name. Corresponds with the B<-R> startup option.
3070
3071See also the discussion on Kerberos Support.
3072
3073=item prompt (string)
3074
3075This variable is used by I<sqsh> to build your current prompt. Any variables
3076contained within B<$prompt> are expanded each time the prompt is displayed. The
3077default value for this is '${lineno}> '. See also the discussion on color
3078support below.
3079
3080=item prompt2 (string)
3081
3082This contents of this prompt are expanded and displayed during interactive use
3083when I<sqsh> requires additional input, such as during a line continuation. The
3084default value is '--> '.
3085
3086=item query_timeout (int)
3087
3088Number of seconds to wait for a query to return data. If the timeout is reached
3089the query is aborted (canceled). See also B<$max_timeout> and the B<-Q> command
3090line option.
3091
3092=item rcfile (path)
3093
3094Contains a colon (:) delimited list of sqsh resource (sqshrc) files. The default
3095setting is /usr/local/etc/sqshrc (unless overridden by the --prefix option when
3096sqsh was compiled) followed by I<$HOME/.sqshrc>).
3097
3098=item readline_histignore (string)
3099
3100If readline support has been compiled into I<sqsh>, you can control which
3101commands or statements on the command line will be filtered from the readline
3102history file specified by B<$readline_history>. It is a colon (:) separated
3103string or a string containing a regular expression that is identified by "RE:".
3104For example:
3105
3106    \set readline_histignore='go:lo:mo:exit:quit:vi:!!:GO'
3107    or
3108    \set readline_histignore='"RE:^[glm]o$|^cd |^exit$|^quit$|^vi$"'
3109
3110The regular expression in the second example starts with I<RE:> and it is
3111recommended to supply the string between quotes and double quotes to prevent
3112expansion and display problems due to the pipe characters. The regular
3113expression is evaluated case insensitive.
3114
3115=item readline_history (string)
3116
3117If readline support has been compiled into I<sqsh>, the contents of the readline
3118line-by-line history will be written to the file specified by the
3119B<$readline_history> variable. The default is I<$HOME/.sqsh_readline>.
3120
3121=item readline_histsize (int)
3122
3123If readline support has been compiled into I<sqsh>, the value of
3124B<$readline_histsize> specifies the number of lines that are saved in the
3125readline line-by-line history. Setting this to a value of 0 causes every line to
3126be saved. The default value is 100.
3127
3128=item real (float-format)
3129
3130Defines the display format (the precision and scale) for all real values
3131displayed by sqsh. The default is '18.6'. Note that values exceeding the
3132defined precision are not truncated, so setting this value too low may cause
3133columns in a result set to be miss-aligned.
3134
3135=item repeat_batch (boolean)
3136
3137When set to B<On> or B<True>, a B<\go> executed with an empty B<SQL Buffer> will
3138cause the previous batch to be re-executed.
3139
3140=item secmech (string)
3141
3142The name of the security mechanism used for user authentication. For instance
3143csfkrb5. When using the B<-Z> option, the name of the security mechanism can be
3144specified, or when no secmech is supplied, the OpenClient will use the default,
3145i.e. the first security entry from the I<$SYBASE/$SYBASE_OCS/config/libtcl.cfg>
3146file. Note that the name used must match the name of the corresponding secmech
3147entry in the I<objectid.dat> file. When the connection to the server is setup,
3148the actual secmech name will be stored in the B<$secmech> variable.
3149
3150=item secure_options (string)
3151
3152Describe the security options used for user authentication security mechanisms.
3153Corresponds to the B<-V> startup option.
3154
3155See also the paragraph on Kerberos Support.
3156
3157=item script (string)
3158
3159If I<sqsh> is run using the B<-i> flag, then this variable contains the name of
3160the script being executed.
3161
3162=item semicolon_cmd (string)
3163
3164When B<$semicolon_hack> (see below) is enabled, the contents of this variable is
3165executed when a semicolon is encountered in the B<SQL Buffer>. This variable
3166defaults to the string 'B<\go>'.
3167
3168=item semicolon_hack (boolean)
3169
3170Toggles on the ability to use a ';' as an in-line command terminator. This
3171feature is not recommended and is only in here because enough users complained.
3172See section B<COMMANDS, In-Line \go>.
3173
3174=item semicolon_hack2 (boolean)
3175
3176Toggles on the ability to use multiple ';' as an in-line command terminator.
3177See section B<COMMANDS, In-Line \go>.
3178
3179=item session (string)
3180
3181The location of the session file that will be processed just before connecting
3182to a server. The variable will be expanded so it may contain environment
3183variables.
3184
3185=item SHELL (string)
3186
3187The name of the shell to be used to execute pipes and to be used by the
3188B<\shell> command (default '/bin/sh').
3189
3190=item statistics (boolean)
3191
3192Setting B<$statistics> to 1 causes timing statistics to be displayed upon the
3193successful execution of every batch of SQL. This variable may also be set via
3194the B<-p> command line flag, or by supplying B<-p> to the B<\go> command.
3195B<$statistics> defaults to 0.
3196
3197=item style (string)
3198
3199Selects result set display style. Currently eight styles are supported. The
3200B<horiz> (which may also be defined as B<hor> or B<horizontal>), closely
3201resembles the output of isql, with the traditional columnar output.
3202
3203The B<vert> (or B<vertical>) style rotates the output, so that every line is
3204represented by a column name followed by a column value. This is nice for
3205looking at particularly wide output.
3206
3207The B<bcp> style displays results in a format amenable to bcp'ing the result
3208set back into another table. That is, every column value is separated by
3209B<$bcp_colsep> with the final column separated by B<$bcp_rowsep> followed by a
3210newline (\n). If B<$bcp_colsep> or B<$bcp_rowsep> are not defined then '|'
3211is used as the default separator. Note that this output does not work well with
3212COMPUTE columns, and uses the default conversion methods for all data types
3213(that is, B<datetime> columns may truncate the millisecond).
3214
3215The B<csv> display style outputs all result sets in the form of a comma
3216separated construct. This mode is ideal to import result sets into spreadsheet
3217programs, for instance.
3218
3219The B<html> display style outputs all result sets in the form of an HTML <TABLE>
3220construct. This mode is ideal for the use of sqsh as a CGI application.
3221
3222The B<meta> display style outputs only the meta-data information associated with
3223the result and discards the actual row results. This mode is useful for
3224debugging the result sets generated from a full passthru Open Server gateway, or
3225for those interested in what is really coming back from the server.
3226
3227The B<pretty> display style generates a fluffy table-like output using regular
3228ASCII characters for borders. This mode does not perform any explicit column
3229wrapping, like the B<horiz> display mode. However, the B<$colwidth> variable can
3230be used to control the maximum width of a given column on the screen. If the
3231column exceeds B<$colwidth> characters wide, it is wrapped in a relatively
3232visually appealing manner. Note that B<$colwidth> may be exceeded if there is
3233enough screen width to hold the columns without wrapping.
3234
3235The B<none> display style suppresses all results from being displayed (however
3236it does actually retrieve result information from the SQL Server). This is
3237particularly useful when used with the B<-p> flag (or the B<$statistics>
3238variable) for gathering accurate performance statistics.
3239
3240=item term_title (string)
3241
3242When this variable is set, sqsh will reset the name of the current terminal
3243(xterm) window it is running in. Works for xterm, rxvt, putty and MS-Windows CMD
3244windows. The name consists of the sqsh startup name appended with the expanded
3245value of the B<$term_title> variable.
3246
3247=item thresh_display (int)
3248
3249Sets the minimum SQL Server error severity that will display a message to the
3250user, the default is 0 and valid ranges are between 0 and 22, inclusive.
3251
3252=item thresh_exit (int)
3253
3254Defines the maximum number of errors of severity level B<$thresh_fail> that may
3255be encountered before sqsh aborts. This is useful primarily for non-interactive
3256scripts, but is allowed on an interactive session. Setting B<$thresh_exit> to a
3257value of 0 disables this feature. See section B<EXIT STATUS> for details.
3258
3259=item thresh_fail (int)
3260
3261Sets the minimum SQL Server severity level that is to be considered a failed
3262batch. The minimum for this value is 0 (meaning any error that is not an
3263information message), and the maximum is 22. Whenever B<$thresh_fail> is
3264crossed, the variable B<$batch_failcount> is incremented by 1. See section
3265B<EXIT STATUS> for details.
3266
3267=item time (date-spec)
3268
3269This variable may be set with a time format (see the man page for B<date(1)>),
3270and the variable expands to the current time in the supplied format. The default
3271format for this variable is %H:%M:%S (e.g. 14:32:58).
3272
3273=item timefmt (date-spec)
3274
3275This variable may be set with a time format similar to B<$time> and
3276is used to control the display format of all SQL Server TIME and BIGTIME
3277columns. (Similar to B<$datetime>.) Note that only 63 bytes are available in
3278total for the expanded string and the remainder will be truncated.
3279
3280=item tmp_dir (path)
3281
3282This contains the directory to which temporary files used internally by I<sqsh>
3283are to be written. These files are generated either during buffer editing (the
3284B<\buf-edit> command), or to maintain output defer files for background jobs.
3285The default value for this variable is /tmp.
3286
3287=item usedbcheck (boolean)
3288
3289When this variable is set to 'On' (default is 'Off') and a database name is
3290provided with the -D parameter and sqsh is run in batch mode, i.e.
3291non-interactive, then a check will be performed if the specified database is
3292accessible, otherwise sqsh is aborted with exit code 254. Also the following
3293error message will be shown:
3294
3295B<sqsh: ERROR: Unable to use database '...' in batch mode>
3296
3297This is to prevent that a SQL script is inadvertently executed in the wrong
3298database, usually the default database of the login (master for example).
3299
3300=item username (string)
3301
3302The name of the user currently connected to the database.
3303
3304=item version (none)
3305
3306This read-only variable contains the current version number. (sqsh-2.1.7)
3307
3308=item width (int)
3309
3310The current width of the SQL output.
3311
3312=item xgeom (string/int)
3313
3314If X11 support is compiled into I<sqsh>, this value is used to configure the
3315default window size (in characters) of the X display. This variable must be of
3316the format B<WxH> or just B<W>, where B<W> is the width of the window and B<H>
3317is the height of the window. If the height of the window is not supplied, then
331825 lines is assumed. If B<$xgeom> is not set, then B<$width> is used as the
3319default width and the height is assumed to be 25. If neither is set, then 80x25
3320is assumed.
3321
3322=item xwin_title (string)
3323
3324If X11 support is compiled into I<sqsh> and an X11 result windows is requested
3325by using the B<-x> parameter of the I<\go> or I<\rpc> commands, then this
3326variable will be used to set the title name of the window. Can be temporarily
3327overridden with the B<-T> option of the I<\go> and I<\rpc> commands.
3328
3329=back
3330
3331=head2 Script Execution
3332
3333As with most shells, I<sqsh> allows a file containing SQL and script commands to
3334be executed directly via the magical UNIX B<#!> convention. On most UNIX
3335platforms, when the operating system encounters the bytes B<#!> as the first two
3336bytes of an executable file it will automatically pipe the file through the
3337interpreter specified immediately after the B<#!>. For example, to create an
3338executable I<sqsh> script to run B<sp_who>, you simply need to create a file
3339like so:
3340
3341    #!/usr/local/bin/sqsh -i
3342    sp_who
3343    go
3344
3345Thus, if your B<sp_who> script is executed directly, it will automatically
3346launch "B</usr/local/bin/sqsh -i sp_who>" for you.
3347
3348And, to make things even more flexible, I<sqsh> supports positional parameters,
3349similar to most shells, of the form B<${n}> which will expand to the B<n>th
3350argument to your I<sqsh> script. For example:
3351
3352    #!/usr/local/bin/sqsh -i
3353    sp_who ${1}
3354    go
3355
3356will cause the B<sp_who> stored procedure to be executed with an argument of the
3357first command line parameter supplied to the B<sp_who> shell script.
3358
3359Note that positional parameters I<must> be contained between braces to avoid
3360conflicts with the T-SQL B<money> data type (without the braces, the variable
3361will not be expanded).
3362
3363=head1 EXIT STATUS
3364
3365One of the major complaints of I<isql> is that it provides no facility to detect
3366when an error condition occurred while it is performing processing. I<sqsh>
3367provides a rather complex, but flexible mechanism for returning meaningful
3368information concerning its reason for exit in the form of an exit status (see
3369B<exit(3)>).
3370
3371When I<sqsh> begins execution two handlers are associated with the current
3372connection to the database, one is a message handler which is responsible for
3373displaying the text of any SQL Server messages or errors, and the other is an
3374error handler, which is responsible for determining what to do with an error
3375condition (bear with me, these are only loose descriptions). And, associated
3376with each message and error condition is a severity level, between 0 and 22
3377(informational message to fatal condition).
3378
3379Associated with these two message handlers are several variables that are used
3380to either control their behavior, or are used as indicators by the message
3381handler:
3382
3383=over 4
3384
3385=item $thresh_display
3386
3387This variable is used by the message handler to determine the minimum error
3388severity which will cause a message to be displayed. By default this is 0, which
3389will display all messages (with a couple of exceptions). Setting this to 1, for
3390example, would suppress informational messages such as the output of
3391B<set showplan on>.
3392
3393=item $thresh_fail
3394
3395This variable is used by the error handler to determine which error severity is
3396considered by I<sqsh> to be a failure. Normally, this defaults to 11 which
3397indicates that any error, other than informational messages, is a failure. The
3398next variable will explain the importance of this value.
3399
3400=item $batch_failcount
3401
3402This variable should be considered read-only, and contains the total number of
3403times that batches have caused an error of severity B<$thresh_fail> or more. The
3404only value that is valid to explicitly set this value to, is "" (the empty
3405string), which will reset this value to 0, any other value may have
3406unpredictable results.
3407
3408=item $thresh_exit
3409
3410This variable is used to determine the limit at which B<$batch_failcount> will
3411cause I<sqsh> to exit. If B<$thresh_exit> is 0, then this feature is disabled.
3412In other words, if B<$batch_failcount = $thresh_exit> and B<$thresh_exit> is
3413greater than 0, then I<sqsh> will exit, returning B<$batch_failcount> as an exit
3414status.
3415
3416Note that, unless B<$exit_failcount> is set to 1, I<sqsh> will exit with 0 if
3417the total number of failures does not reach B<$thresh_exit>.
3418
3419=item $exit_failcount
3420
3421This variable is used only when I<sqsh> would normally exit with a success
3422status (0), this causes it to instead exit with a value of B<$batch_failcount>
3423(which may, itself, be 0).
3424
3425=item $exit_value
3426
3427When this variable is non-zero, it will override the B<$exit_failcount> and
3428B<$batch_failcount> values and just exit the value of B<$exit_value>. This
3429variable may be explicitly set using the B<\set> command, or implicitly using
3430B<\exit x> and its aliased counterparts.
3431
3432=back
3433
3434To recap, here is a list of error codes that may be returned by I<sqsh> upon
3435exit, and the reason that they could be returned:
3436
3437=over 4
3438
3439=item - 0 -
3440
3441No error has been encountered.
3442
3443=item - 1...253 -
3444
3445Between 1 and 253 batches have failed (if you run more than 253 batches, the
3446exit status of sqsh is undetermined...I may fix this in the future).
3447
3448=item - 254 -
3449
3450An explicit B<\abort> was called, or a SIGINT (^C) was issued during a
3451non-interactive session.
3452
3453=item - 255 -
3454
3455A general error condition has occurred, such as a bad command line argument to
3456sqsh, memory allocation failure, file access error, etc.
3457
3458=back
3459
3460The following sections provide detailed examples of combinations of variable
3461settings and the results produced upon exit with certain failure conditions. It
3462is assumed the B<$exit_value> variable contains 0 in the next examples.
3463
3464=over 4
3465
3466=item thresh_display=0, thresh_fail=0, thresh_exit=1
3467
3468With this combination, all error messages will be displayed as they happen, and
3469every error will be considered an failure condition. Upon reaching the first
3470error, I<sqsh> will abort with an exit status of 1, or the total number of
3471failures (the B<$batch_failcount> variable). However, if nothing goes wrong
3472during the whole process, a zero is returned.
3473
3474=item thresh_display=0, thresh_fail=0, thresh_exit=3
3475
3476This combination will cause all error conditions to be displayed and all of them
3477to be considered a failure condition. Upon reaching three total failed batches,
3478I<sqsh> will exit with a status of 3. However if 0, 1, or 2 batches fail, then 0
3479is returned.
3480
3481=item thresh_display=22, thresh_fail=0, thresh_exit=3
3482
3483This behaves the same as the previous example, with the exception that all error
3484messages will be suppressed from being displayed. This is particularly useful if
3485you just care about the exit value more than the actual error.
3486
3487=item thresh_display=0, thresh_fail=2, thresh_exit=1
3488
3489This will cause the first error of severity 2 or higher to be displayed and
3490cause I<sqsh> to exit with a failure condition of 1.
3491
3492=item thresh_display=0, thresh_fail=0, thresh_exit=3, exit_failcount=1
3493
3494This is identical to the second example, above, however B<sqsh> will return the
3495total number of batches that failed even if B<$batch_failcount> does not reach
34963.
3497
3498=item exit_value=nonzero
3499
3500This will override all conditions explained above and just exit the specific
3501value.
3502
3503=back
3504
3505=head1 MISCELLANEOUS
3506
3507=head2 Colorizing sqsh prompts
3508
3509Color codes are presented as a string like {1;2;3}. If sqsh encounters a {
3510(curly brace) in the prompt string it will assume a color-code is supplied and
3511will act as such. No checks will be performed on the validity of the color-code
3512definition itself. The color definition consists of three values separated by a
3513semicolon.
3514
3515The first code defines the Color Attribute Code with possible values: 0=none
35161=bold
3517The second value defines the Text Color Code: 30=black 31=red 32=green 33=yellow
351834=blue 35=magenta 36=cyan 37=white
3519The third value defines the Background Color Code: 40=black 41=red 42=green
352043=yellow 44=blue 45=magenta 46=cyan 47=white The last color-code for the
3521background may be omitted.
3522Not all color and attribute combinations will present good results, depending on
3523your terminal type and color scheme. But the following values work OK on a xterm
3524with a creamy white background color in Linux as well as rxvt in Cygwin with a
3525black background window:
3526
3527    Prompt: Blue text in white background "{0;34;47}"
3528    Command text: Yellow text             "{0;33}"
3529    Command text: Default text color      "{0}"
3530
3531sqsh will translate the color-codes to an actual color-code string that is
3532presented to readline: for example "\001\033[0;36;47m\002". Note that if you
3533want to use curly brackets in your prompt, you have to escape colorization by
3534specifying a double brace, like {{...}}. For example:
3535
3536    \set prompt_color='{0;34;47}'
3537    \set text_color='{0}'
3538    \set prompt='$prompt_color{{$DSQUERY.$username.$database.$lineno}}>$text_color '
3539
3540Color support is automatically available if sqsh is compiled and linked with
3541readline support enabled.
3542
3543=head1 FILES
3544
3545Defaults: $HOME/.sqshrc, $HOME/.sqsh_session, $HOME/.sqsh_history,
3546$HOME/.sqsh_readline, $HOME/.sqsh_words, $tmp_dir/sqsh-dfr.*,
3547$tmp_dir/sqsh-edit.* These can all be modified using the internal I<sqsh>
3548variables described above.
3549
3550
3551=head1 BUGS
3552
3553The addition of flow-of-control expressions has extended sqsh I<way> beyond the
3554scope of its original design, and it is quite obvious from using the features
3555they are hacked in and are rather clunky (although still quite usable). As a
3556result, the processing of these expressions is rather slow (when compared to
3557bourne shell), and the error reporting doesn't lend itself to debugging large
3558scripts. The development of 1000+ line scripts is discouraged.
3559
3560The combination of backgrounding and pipes does not work properly right now.
3561What happens is, when a background job is run that incorporates a pipe-line,
3562I<sqsh> will suspend until the job is complete, which is obviously not what
3563you desire. To test this, try the following:
3564
3565    1> select * from syscolumns
3566    2> go | grep id &
3567
3568You will find that you do not get your prompt back until the job completes.
3569The same is more ore less true for pipes being used with the \do command:
3570
3571    1> select name from master..sysdatabases
3572    2> \do | grep syb
3573
3574This will not give you a prompt anymore until the block completes with \done.
3575So you are typing the do block itself in the dark and there is no possiblity
3576to edit a do block or retrieve a do block from the history list.
3577So you may have typed (hopefully without syntax errors):
3578
3579    \echo #1
3580    \done
3581
3582After \done is processed the results will be displayed followed by a fresh
3583prompt.
3584
3585Please report any other bugs to http://sourceforge.net/p/sqsh/bugs
3586Feature requests may be posted to http://sourceforge.net/p/sqsh/feature-requests
3587