.\" Automatically generated by Pod::Man 2.22 (Pod::Simple 3.07) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .ie \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} .el \{\ . de IX .. .\} .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "sqsh 1" .TH sqsh 1 "2014-03-12" "2.5" "sqsh-2.5" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" sqsh \- Interactive database shell (version 2.5) .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 10 \& sqsh [[options]] [[args......]] \& [ \-a count ] \& [ \-A packet_size ] \& [ \-b ] \& [ \-B ] \& [ \-c [cmdend] ] \& [ \-C sql ] \& [ \-d severity ] \& [ \-D database ] \& [ \-e ] \& [ \-E editor ] \& [ \-f severity ] \& [ \-G tds_version ] \& [ \-h ] \& [ \-H hostname ] \& [ \-i filename ] \& [ \-I interfaces ] \& [ \-J charset ] \& [ \-k keywords ] \& [ \-K keytab] \& [ \-l debug_flags ] \& [ \-L var=value ] \& [ \-m style ] \& [ \-n on|off ] \& [ \-N appname ] \& [ \-o filename ] \& [ \-p ] \& [ \-P [password] ] \& [ \-Q query_timeout ] \& [ \-r [sqshrc] ] \& [ \-R server principal ] \& [ \-s colsep ] \& [ \-S server ] \& [ \-t [filter] ] \& [ \-T login_timeout ] \& [ \-U username ] \& [ \-v ] \& [ \-V [bcdimoqru]] \& [ \-w width ] \& [ \-X ] \& [ \-y directory ] \& [ \-z language ] \& [ \-Z [secmech|default|none] ] .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Sqsh (pronounced skwish) is short for SQshelL (pronounced s\-q-shell), and is intended as a replacement for the venerable 'isql' program supplied by Sybase. It came about due to years of frustration of trying to do real work with a program that was never meant to perform real work. .PP Sqsh is much more than a nice prompt, it is intended to provide much of the functionality provided by a good shell, such as variables, aliasing, redirection, pipes, back-grounding, job control, history, command substitution, and dynamic configuration. Also, as a by-product of the design, it is remarkably easy to extend and add functionality. .SH "OPTIONS" .IX Header "OPTIONS" The following options may be used to adjust some of the behavior of sqsh, however a large portion of the configuration options are available only through environment variables which may be set at runtime or via a .sqshrc file. .PP Options may also be supplied in the \s-1SQSH\s0 environment variable. This variable is parsed prior to parsing the command line, so in most cases the command line will override the contents of the variable. Be aware that for options which are allowed to be supplied multiple times, such as \fB\-c\fR, supplying them both in a variable and on the command line will be the same as supplying them multiple times on the command line. .IP "\-a count" 4 .IX Item "-a count" Sets the maximum \fIcount\fR of failures (as determined by the \fB\f(CB$thresh_fail\fB\fR variable) that may occur before sqsh will abort. Setting this to 0 indicates that sqsh should not exit on errors. This value defaults to 0 and may also be set using the \fB\f(CB$thresh_exit\fB\fR variable. See section \fB\s-1EXIT\s0 \s-1STATUS\s0\fR for details. .IP "\-A packetsize" 4 .IX Item "-A packetsize" Specifies the size of the network \s-1TDS\s0 packets used to communicate with the \s-1SQL\s0 server. This value must be between 512 and 8192, and be a multiple of 512. Check your \s-1SQL\s0 Server configuration to determine supported packet sizes. This value may also be specified at run-time using the \fB\f(CB$packet_size\fB\fR variable. .IP "\-b" 4 .IX Item "-b" Suppress the banner message upon startup. This is unnecessary in cases where stdout has been redirected to a file. This option may also be set via the \&\fB\f(CB$banner\fB\fR variable. .IP "\-B" 4 .IX Item "-B" Turns off all buffering of stdin, stdout, and stderr. This feature allows sqsh to be run from an interactive control script such as chat and expect. .IP "\-c [cmdend]" 4 .IX Item "-c [cmdend]" Internally sqsh provides the command \fB\ego\fR to send a batch of \s-1SQL\s0 to the database and provides a single alias, \fBgo\fR for this command. Each time \&\fIcmdend\fR is supplied a new alias for \fB\ego\fR is established. .IP "\-C sql" 4 .IX Item "-C sql" Causes the \fIsql\fR command to be executed by sqsh, similar to the same behavior exhibited by the \-i flag. This \fIsql\fR statement may not contain double quotes (this limitation may be lifted in a future release of sqsh). .IP "\-d severity" 4 .IX Item "-d severity" Sets the minimum \s-1SQL\s0 Server error severity that will be displayed to the user. The default is 0, and valid ranges are from 0 to 22. This may also be set using the \fB\f(CB$thresh_display\fB\fR variable. See section \fB\s-1EXIT\s0 \s-1STATUS\s0\fR. .IP "\-D database" 4 .IX Item "-D database" Causes sqsh to attempt to start with your database context set to \fIdatabase\fR rather than your default database (usually master). This may also be set using the \fB\f(CB$database\fB\fR variable. .IP "\-e" 4 .IX Item "-e" Includes each command issued to sqsh to be included in the output. This option may also be set via the \fB\f(CB$echo\fB\fR variable (which is unrelated to the \fB\eecho\fR command). .IP "\-E editor" 4 .IX Item "-E editor" Set the default editor to \fIeditor\fR. This may also be set using the \s-1UNIX\s0 environment variable \fB\f(CB$EDITOR\fB\fR to the name of the editor desired. .IP "\-f severity" 4 .IX Item "-f severity" Sets the minimum \fIseverity\fR level considered a failure by sqsh. This is the same as setting the \fB\f(CB$thresh_fail\fB\fR variable. See section \fB\s-1EXIT\s0 \s-1STATUS\s0\fR for details. .IP "\-G tds_version" 4 .IX Item "-G tds_version" Set the \s-1TDS\s0 version to use. Valid versions are 4.0, 4.2, 4.6, 4.9.5, 5.0 and freetds additionally supports versions 7.0 and 8.0. The specified value is assigned to the variable \fB\f(CB$tds_version\fB\fR. Input validation is not performed by sqsh. However, when an invalid \s-1TDS\s0 version is specified, the default version of 5.0 will be used. After a session is setup, the variable \fB\f(CB$tds_version\fB\fR will be set to the \s-1TDS\s0 version in effect. The variable will not be available if option \&\-G is not used. Meant for test and debugging purposes only. .Sp \&\s-1TDS\s0 stands for Tabular Data Stream and is the communication protocol Sybase and Microsoft uses for Client-Server communication. .IP "\-h" 4 .IX Item "-h" Turns off column headers and trailing \*(L"(# rows affected)\*(R" from batch output. .IP "\-H hostname" 4 .IX Item "-H hostname" Sets the client hostname as reported in sysprocesses. This may also be set via the \fB\f(CB$hostname\fB\fR variable. .IP "\-i filename" 4 .IX Item "-i filename" Read all input from \fIfilename\fR rather than from stdin. .IP "\-I interfaces" 4 .IX Item "-I interfaces" When a connection is established to the database, the \fIinterfaces\fR file is used to turn the value of \fB\f(CB$DSQUERY\fB\fR into the hostname and port to which the connection will be made, by default this is located in \fB\f(CB$SYBASE\fB\fR/interfaces. This flag allows this default to be overridden. .IP "\-J charset" 4 .IX Item "-J charset" Specifies the character set to be used on the client side to communicate with \&\s-1SQL\s0 Server. This may also be set using the \fB\f(CB$charset\fB\fR environment variable. .IP "\-k keywords" 4 .IX Item "-k keywords" Specifies a file containing a list of keywords to be used for keyword tab completion, if readline support has been compiled into sqsh. This file may also be set via the \fB\f(CB$keyword_file\fB\fR variable, which defaults to \fB\f(CB$HOME\fB\fR/.sqsh_words. .IP "\-K keytab" 4 .IX Item "-K keytab" Kerberos support. Specify the keytab file name for \s-1DCE\s0. .Sp See the Kerberos Support section below for details. .IP "\-l debug_flags" 4 .IX Item "-l debug_flags" If sqsh has been compiled with \-DDEBUG, this option may be used to turn on and off debugging options. See the \fB\f(CB$debug\fB\fR variable, below. .IP "\-L var=value" 4 .IX Item "-L var=value" Sets the value of \fB\f(CB$var\fB\fR to \fIvalue\fR. This may be used to set the value of any sqsh variable even if an explicit command line variable is supplied for setting the variable. The \fB\-L\fR flag may be used to set the value of non-configuration variables as well. .IP "\-m style" 4 .IX Item "-m style" Changes the current display style to \fIstyle\fR. Currently supported styles are \&\fBhoriz\fR, \fBvert\fR, \fBbcp\fR, \fBcsv\fR, \fBhtml\fR, \fBmeta\fR, \fBpretty\fR and \fBnone\fR. The current display style may also be set using the \fB\f(CB$style\fB\fR variable or via the \&\fB\-m\fR flag to the \fB\ego\fR command. .IP "\-n on|off" 4 .IX Item "-n on|off" Enables chained transaction mode on connect (if set to on). Chained transaction mode is also known as \*(L"AutoCommit off\*(R" mode. .IP "\-N appname" 4 .IX Item "-N appname" Set the application name sqsh uses to identify itself to the \s-1SQL\s0 server. The application name can be retrieved from the server using the column \&\fBprogram_name\fR of the master.dbo.sysprocesses table. Defaults to \fIsqsh\-2.1.7\fR. .IP "\-o filename" 4 .IX Item "-o filename" Redirects all output to \fIfilename\fR rather than stdout. .IP "\-p" 4 .IX Item "-p" Display performance statistics upon completion of every \s-1SQL\s0 batch. This option may also be turned on via the \fB\f(CB$statistics\fB\fR variable, or by supplying the \fB\-p\fR flag to the \fB\ego\fR command. .IP "\-P [password | \-]" 4 .IX Item "-P [password | -]" The Sybase \fIpassword\fR for \fIusername\fR required to connect to \fIserver\fR (default, \s-1NULL\s0). The \fIpassword\fR may also be set via \fB\f(CB$password\fB\fR. Supplying a password of '\-' causes the password to be read from the first line of stdin. .Sp sqsh takes pains to hide the password from any user trying to view the command line used to launch sqsh, so using \fB\-P\fR should not constitute a security hole. Alternatively, you can store your default password in .sqshrc file which is not readable by anyone other than yourself. (chmod 600 .sqshrc) .IP "\-Q value" 4 .IX Item "-Q value" Query timeout value (equivalent to isql's \-t option). If set, will timeout a long running query. Maps to the \fB\f(CB$query_timeout\fB\fR variable. .Sp For example: .Sp .Vb 9 \& sqsh \-SASE1502 \-Usa \-P \-Q30 \& ASE1502.sa.master.1> cd tix \& ASE1502.sa.tix.1> select count(*) from E_TIX; \& Open Client Message \& Layer 1, Origin 2, Severity 2, Number 63 \& ct_results(): user api layer: internal Client Library error: \& Read from the server has timed out. \& ASE1502: Query or command timeout detected, command/batch cancelled \& ASE1502: The client connection has detected this 1 time(s). .Ve .Sp See also the \fB\f(CB$max_timeout\fB\fR variable, which controls the number of times a timeout may occur on the current connection before the session is aborted. .IP "\-r [sqshrc]" 4 .IX Item "-r [sqshrc]" Specifies an alternate \fI.sqshrc\fR file to be processed, rather than the default. If no \fIsqshrc\fR is supplied following \fB\-r\fR, then no initialization files are processed. This flag \fBmust\fR be the first argument supplied on the command line, all other instances will be ignored. .IP "\-R server_principal" 4 .IX Item "-R server_principal" Kerberos support: Specifies a \fIserver principal\fR to use for network (Kerberos) authentication, if the server name in the interfaces file differs from the real server name. .Sp See the Kerberos Support section below for details. .IP "\-s colsep" 4 .IX Item "-s colsep" Causes the string \fIcolsep\fR to be used to delimit \s-1SQL\s0 column output columns, this defaults to \*(L" \*(R". .IP "\-S server | host:port[:filter]" 4 .IX Item "-S server | host:port[:filter]" The name or the address of the Sybase \fIserver\fR to connect. The default of this is the external environment variable \fB\f(CB$DSQUERY\fB\fR. If neither \fB\-S\fR nor \&\fB\f(CB$DSQUERY\fB\fR is set then defaults to \*(L"\s-1SYBASE\s0\*(R". This value may also be set via the internal variable \fB\f(CB$DSQUERY\fB\fR. The servername must exist in the interfaces or sql.ini file. As an alternative it is also possible to specify the target server as \fBhost:port[:filter]\fR where \fIhost\fR may also be an \s-1IP\s0 address. Note that \fBfilter\fR may be defined in \f(CW$SYBASE\fR/$SYBASE_OCS/config/libtcl[64].cfg. For example: .Sp .Vb 3 \& [FILTERS] \& ssl=libsybfssl.so \& ssl64=libsybfssl64.so .Ve .IP "\-t [filter]" 4 .IX Item "-t [filter]" Enables filtering of command batches through an external program, \fIfilter\fR, and prior to being sent to the \s-1SQL\s0 Server. If \fIfilter\fR is not supplied, then \&\fB\f(CB$filter_prog\fB\fR is used (default is 'm4 \-'). This value may also be set via the \&\fB\f(CB$filter\fB\fR and \fB\f(CB$filter_prog\fB\fR variables. .IP "\-T value" 4 .IX Item "-T value" Specifies the login timeout (similar to isql's \-l flag). If set specifies the number of seconds \fIsqsh\fR will wait before timing out a login request. Maps to the \fB\f(CB$login_timeout\fB\fR variable. .IP "\-U username" 4 .IX Item "-U username" The Sybase \fIusername\fR to connect to the database as, this defaults to the username of the user running \fIsqsh\fR. The \fIusername\fR may also be set via the \&\fB\f(CB$username\fB\fR variable. .IP "\-v" 4 .IX Item "-v" Displays the version number, \fB\f(CB$version\fB\fR, and exits. .IP "\-V [bcdimoqru]" 4 .IX Item "-V [bcdimoqru]" Kerberos support: Specify the security options to use. .Sp See the Kerberos Support section below for details. .IP "\-w width" 4 .IX Item "-w width" The maximum output \fIwidth\fR of a displayed result set, this defaults to your screen width in interactive mode. .IP "\-X" 4 .IX Item "-X" Initiates the login connection to the server with client-side password encryption (if supported). If either \s-1SQL\s0 Server does not recognize this option, or if the version of CT-Lib used to compile \fIsqsh\fR does not support this option, then it will be ignored. This option may also be set using the \&\fB\f(CB$encryption\fB\fR environment variable. .IP "\-y directory" 4 .IX Item "-y directory" Specifies a \s-1SYBASE\s0 \fIdirectory\fR to use other than the value of \fB\f(CB$SYBASE\fB\fR in order to find the interfaces file. .IP "\-z language" 4 .IX Item "-z language" Specifies an alternate \fIlanguage\fR to display sqsh prompts and messages. Without the \fB\-z\fR flag, the server's default language will be used. This may also be set using the \fB\f(CB$language\fB\fR variable. .IP "\-Z [secmech|default|none]" 4 .IX Item "-Z [secmech|default|none]" Kerberos support: Specify the security mechanism to use. .Sp See the Kerberos Support section below for details. .IP "args..." 4 .IX Item "args..." If sqsh is run with the \fB\-i\fR flag specifying an input file to be processed (rather than initiating an interactive session), arguments may be supplied on the command line to be passed to the input file. These arguments may be accessed using the variables ${0}, ${1}, ... (see the \fBVariables\fR section, below, for more information). .SS "Initialization" .IX Subsection "Initialization" Upon startup, sqsh initializes all internal environment variables, commands, and aliases to their default values, it then looks in the system-wide configuration file, /etc/sqshrc, followed by a local configuration file \&\fB\f(CB$HOME\fB\fR/.sqshrc (this may be overridden via the \s-1SQSHRC\s0 external environment variable). If this file is found it is executed just like a script would be using the \fB\-i\fR flag. .PP The \fI.sqshrc\fR file may contain anything that could normally be typed at the prompt, however it should be noted that at the time this file is read sqsh has yet to establish a connection to the database, however most commands that perform database activity, such as \fB\ego\fR will attempt to establish a database connection when executed (it may also prompt you for a password if necessary). Also, if database activity is required within this startup file, the \fB\econnect\fR command (see \fB\s-1COMMANDS\s0\fR, below) may be executed. .PP After the \fI.sqshrc\fR file has been executed, \fIsqsh\fR then parses any command line options (thus any variables set in your \fI.sqshrc\fR file may be overridden by command line options). Following that, if \fIsqsh\fR is run in interactive mode (i.e. without \fB\-i\fR and if stdin is attached to a tty), it then looks for the file provided by the \fB\f(CB$history\fB\fR variable and loads the contents of that file into the history buffers. (see \fB\s-1BUFFERS\s0\fR, below). .PP Immediately prior to establishing a connection to the database (either during startup, or by an explicit \fB\econnect\fR or \fB\ereconnect\fR command), the file \&\fB\f(CB$HOME\fB\fR/.sqsh_session is executed. The name of this file may be overridden using the \fB\f(CB$session\fB\fR variable. .SS "Command line" .IX Subsection "Command line" When a line is first read by \fIsqsh\fR, the first word is separated from the line. This word is then expanded of all variables (see \fBVariable Substitution\fR, below), followed by command expansion (see \fBCommand Substitution\fR, below). The first word of the resulting string is then analyzed to see if it is either a valid \fIsqsh\fR command or alias. .PP The \fIsqsh\fR command line follows many of the same rules as Bourne shell, allowing file redirection, pipelining, command substitution, and back-grounding via the same syntax. .SS "Comments" .IX Subsection "Comments" Any line beginning with a \fB#\fR followed by a non-alphanumeric character (any character other than 0\-9, a\-z, A\-Z, and _) causes the entire line to be ignored. Because of the possible collision with T\-SQL session specific temp-table names, the line will not be ignored if the first character following the \fB#\fR, is alphanumeric. .SS "Quoting" .IX Subsection "Quoting" Quoting is used to prevent the interpretation of special keywords or characters to sqsh, such as white-space, variable expansion, or command substitution. There are three types of quoting, \fIescape\fR, \fIsingle-quotes\fR, and \fIdouble-quotes\fR. .PP Enclosing characters in single quotes preserves the literal interpretation of each character contained within the quotes. A single quote may not appear within single quotes, even when preceded by an escape. For example: .PP .Vb 1 \& 1> \eecho I can not expand \*(Aq$username\*(Aq .Ve .PP outputs .PP .Vb 1 \& I can not expand $username .Ve .PP The characters \e\e are used to escape the meaning (and thus prevent the interpretation) of the character immediately following them. The \e character itself may be escaped. For example: .PP .Vb 1 \& 1> \eecho I can\e\e\*(Aqt expand \*(Aq$username\*(Aq .Ve .PP outputs .PP .Vb 1 \& I can\*(Aqt expand $username .Ve .PP The escape character may also be used to escape a new-line in order to perform a line continuation, in this case the new-line is discarded and the continued line is automatically appended to the previous line, for example: .PP .Vb 3 \& 1> \eecho Hello \e\e \& \-\-> World! \& Hello World! .Ve .PP Enclosing characters in double quotes preserves the literal meaning of all characters within them with the exception of \fB$\fR, \fB'\fR, and \fB\e\e\fR. A double quote may be contained within double quotes by escaping it. .PP .Vb 1 \& 1> \eecho "\e\e"I can\*(Aqt deny it, I like $username\e\e", she said" .Ve .PP prints out .PP .Vb 1 \& "I can\*(Aqt deny it, I like gray", she said .Ve .SS "Expansion" .IX Subsection "Expansion" After a line of input has been read, \fIsqsh\fR attempts to expand the line of any aliases (see \fBAliasing\fR, below), following that it attempts to determine if the line begins with a command keyword. Once a line has been determined to contain a command name it has three types of expansion performed to it: \fIvariable substitution\fR, followed by \fIcommand substitution\fR respectively. Finally, if a tilde was provided on the command line, then \fItilde expansion\fR will be performed and the \fB~\fR will be substituted with the corresponding \fB\s-1HOME\s0\fR directory name. .PP .Vb 1 \& 1> \eecho ~sybase/err.log .Ve .PP may result in \fI/home/sybase/err.log\fR for example. .PP .Vb 2 \& 1> exec sp_helpdb \& 2> go > ~/db.log .Ve .PP may result in a file \fI/export/home/dba/db.log\fR for example, depending on the Unix login and the exact \s-1OS\s0 you are using. Following this expansion the command line is separated into words and the command is executed. .SS "Variable Substitution" .IX Subsection "Variable Substitution" The character $ is used to indicate variable substitution or expansion within a word. These variables may be assigned values by the \fB\eset\fR command like so: .PP .Vb 1 \& 1> \eset name=value .Ve .PP \&\fIname\fR may be a character or underscore followed by any combination of characters, digits, or underscore, and may not contain any special characters, such as (') and ("). The restriction on the first character being a digit is introduced because \s-1SQL\s0 allows the representation of money data types as \f(CW$nn\fR.nn where n is a digit. .PP \&\fIvalue\fR may contain anything, however if it is to include white-space, then it must be quoted (see \fBWords & Quoting\fR, above). Note that in order to prevent the expansion of a variable use either single quotes, or two \e's, like thus: .PP .Vb 2 \& 1> \eecho \e\e$name \& $name .Ve .PP Variables may be referenced in one of two ways: .PP \&\f(CW$variable\fR In this manner all characters, digits, and underscores are treated as the \fIname\fR of the variable until another type of character is reached (either a special character, or a white-space). ${variable} The braces are required only when \fIvariable\fR is followed by a letter, digit, or underscore that is not to be interpreted as part of its name. Note that the same effect may be achieved using double quotes. .PP It should be noted that because the variables are expanded prior to breaking the command line into words, if the contents of the variable contain white spaces, they are treated as significant by the parser. In the following example: .PP .Vb 2 \& 1> \eset x="1 2 3" \& 1> \eecho $x .Ve .PP the \fB\eecho\fR command receives three arguments, \*(L"1\*(R", \*(L"2\*(R", and \*(L"3\*(R", although it looks as if only one argument was passed to it. This behavior is consistent with most shells (such as csh, bourne shell, etc.). .SS "Command Substitution" .IX Subsection "Command Substitution" \&\fISqsh\fR supports a second form of expansion called \fIcommand substitution\fR. This form of expansion substitutes a command on the command line with the output of the external \s-1UNIX\s0 command. This expansion may be achieved by placing the command line to be executed in back-quotes (`). For example: .PP .Vb 3 \& 1> \eset password=\`/sybase/bin/getpwd $DSQUERY\` \& 1> \eecho $password \& ilikepickles .Ve .PP This example, the external program \fB/sybase/bin/getpwd\fR is executed with the current contents of the \fB\f(CB$DSQUERY\fB\fR environment variable, the entire expression is then replaced with the output of \fBgetpwd (ilikepickles)\fR prior to executing the \&\fB\eset\fR command. By default, the output of the substituted command is first broken into words according to the contents of the \fB\f(CB$ifs\fB\fR variable prior to assembling together back into the command line. So, by overriding the contents of \fB\f(CB$ifs\fB\fR you may affect the behavior of the substitution process. .PP For example: .PP .Vb 3 \& 1> \eset ifs=":" \& 1> \eecho \`echo hello:how:are:you\` \& hello how are you .Ve .PP This mechanism is frequently useful for parsing input files, such as \&\fB/etc/passwd\fR into fields. .SS "Input/Output Redirection" .IX Subsection "Input/Output Redirection" As with standard Bourne shell (and most other shells, for that matter), a command's input and output may be redirected using a special notation interpreted by the shell. The following may appear anywhere on the command line, but only redirection that is specified \fIprior\fR to a pipe (|) actually has any effect on the behavior of internal sqsh commands (refer to \fBPipes\fR, below). .IP "word" 4 .IX Item "[n]>word" Associate the output of file descriptor \fIn\fR (stdout, by default) with file \&\fIword\fR. If this file does not exist it is created; otherwise it is truncated to zero length. .IP "[n]>>word" 4 .IX Item "[n]>>word" Append the output of file descriptor \fIn\fR (stdout, by default) to file \fIword\fR, creating it if it does not exist. .IP "[m]>&n" 4 .IX Item "[m]>&n" Redirect the output of file descriptor \fIm\fR (stdout by default), to same output as file descriptor \fIn\fR. The order in which redirections are specified on the command line is significant, as the redirections are evaluated left-to-right. For example: .Sp .Vb 2 \& 1> select * from select /* syntax error */ \& 2> \ego >/tmp/output 2>&1 .Ve .Sp This statement first redirects the standard output of the \fB\ego\fR command to the file \fI/tmp/output\fR, then redirects the stderr to the same file. So, when the commands fails, the error output will be found in the file \fI/tmp/output\fR. .Sp However, by changing the order of redirection, you can completely change the meaning: .Sp .Vb 5 \& 1> select * from select \& 2> \ego 2>&1 >/tmp/output \& Msg 156, Level 15, State 1 \& Server \*(AqSQSH_TEST\*(Aq, Line 1 \& Incorrect syntax near the keyword \*(Aqselect\*(Aq. .Ve .Sp In this case, error output will be sent to stdout, while what would have gone to stdout is redirected to \fI/tmp/output\fR (in this case \fI/tmp/output\fR will be empty). .PP Please read the section on \fBBackground Jobs\fR, below, for detailed info on the interaction between file redirection and background jobs. .SS "Pipes" .IX Subsection "Pipes" A \fIpipeline\fR is a sequence of one or more commands separated by a '|', each command using the stdout of the preceding program for its own stdin. However the first command in the \fIpipeline\fR must be a sqsh command, and all other commands must be external (or \s-1UNIX\s0) programs. Any sqsh command may be run through a pipeline, although for many of them (such as the \fB\eset\fR command) it doesn't really make any sense to do this. The following is an example of a \fIpipeline\fR: .PP .Vb 2 \& 1> select * from syslogins \& 2> \ego | more .Ve .PP This command causes the result set generated by the \fB\ego\fR command to be sent to the \fB\f(BImore\fB\|(1)\fR program, which then sends it to your screen, pausing at each screen full of data (this is the primary reason that I wrote sqsh). .PP There are several peculiarities in the way in which sqsh deals with \fIpipelines\fR as opposed to the way in which standard Bourne shell treats them. .PP Everything following the first occurrence of a pipe (|) character is broken into white-space delimited words, including such special shell commands as '2>&1' and other occurrences of pipes. If there are any variables contained in these words they are expanded following the same quoting rules as described in \&\fBWords & Quoting\fR, above, with the one exception that all quotes are left in place. These words are then reassembled into a single string and shipped off to /bin/sh for processing. .PP In short, sqsh makes no attempt to interpret what follows the first pipe, instead it is shipped off to a \*(L"real\*(R" shell to do the work. The rationale behind this is that I was lazy and didn't feel like writing all of the same bizarre variable handling, &&'ing, ||'ing, grouping, and variable expansion rules that Bourne shell supports, and instead I let Bourne do the dirty work. .PP The advantage of this method is that you can do some very complex stuff after the pipeline, such as: .PP .Vb 2 \& 1> select * from syscolumns \& 2> \ego | (cd /tmp; compress \-c > sysolumns.Z) .Ve .PP Not that I can think of any real reason to do this...but you can if you want to. .SS "Background Jobs" .IX Subsection "Background Jobs" Backgrounding provides a mechanism whereby you may run any sqsh command as a background process and continue working while it runs. Sqsh offers two types of backgrounding: .IP "Deferred" 4 .IX Item "Deferred" In this mode sqsh redirects all output of the background job to a temporary file (located in the directory \fB\f(CB$tmp_dir\fB\fR) while the job is running, so that the output is not intermixed with what you are currently working on. When the job completes you are notified of the process completion and the output may be viewed using the \fB\eshow\fR command. .IP "Non-Deferred" 4 .IX Item "Non-Deferred" This corresponds to the common idea of a background process under \s-1UNIX\s0. In this mode the output of the job is not implicitly redirected for you, and thus may become intermingled with what you are currently working. The mode selection you choose is selectable via the \fB\f(CB$defer_bg\fB\fR variable (which defaults to '1', or \&'On'). Typically the only reason to not use \fIdeferred\fR mode is to prevent large result sets from filling up your file system. .PP To specify that a job be run in the background, simply append a & to the end of the command line, as: .PP .Vb 4 \& 1> sp_long_arduous_proc 1, 30 \& 2> \ego & \& Job #1 running [xxxx] \& 1> .Ve .PP When sqsh encounters the & on the end of the command line it spawns a child process (with a Unix process id of \fIxxxx\fR) then the child process calls the \&\fB\ego\fR. \fB\ego\fR command then establishes a new connection to the database (using the current values of the \fB\f(CB$DSQUERY\fB\fR, \fB\f(CB$username\fB\fR, \fB\f(CB$password\fB\fR variables) and executes the shown query. While the job is executing the commands \fB\ejobs\fR, \&\fB\ewait\fR and \fB\ekill\fR may be used to monitor or alter a currently running job (see section \fB\s-1COMMANDS\s0\fR, below). When any job completes sqsh will display a notification, such as: .PP .Vb 3 \& 1> select count(*) from \& Job #1 complete (output pending) \& 2> .Ve .PP When a job completes, if it had no output, it is immediately considered terminated and will not show up in the current list of running jobs. However if the complete job has pending output, it will continue to be displayed as a running job (with the \fB\ejobs\fR command) until a \fB\eshow\fR is used to display the output of the job. When you exit your parent sqsh session and there are background jobs active then a message is shown: \fBYou have running jobs or pending job output\fR. You have to process all the jobs first before being able to exit sqsh. .PP There is a known bug with job backgrounding when used in conjunction with pipes, please refer to the \fB\s-1BUGS\s0\fR section at the end of the manual. .SS "Buffers" .IX Subsection "Buffers" In normal \fBisql\fR only two buffers are maintained; the buffer into which you are currently typing, and a buffer that contains the last batch executed (this is kept around for when you run 'vi', or 'edit'). .PP Sqsh maintains several distinct sets of buffers: .PP \&\fBWork Buffer\fR: This buffer corresponds directly to the \fBisql\fR work buffer. It is the buffer into which you enter the current batch prior to sending it to the database. .PP \&\fBHistory Buffer\fR: This is actually a chain of 0 or more buffers (configurable by the \fB\f(CB$histsize\fB\fR variable) of the last \fB\f(CB$histsize\fB\fR batches that have been run. This buffer is only maintained when sqsh is run in interactive mode; that is, batches executed using the \fB\-i\fR flag, or executed via redirection from the \&\s-1UNIX\s0 prompt will not be maintained in history (after all, they are already in a file somewhere). .PP If the variable \fB\f(CB$histsave\fB\fR is True (see section \fB\s-1SPECIAL\s0 \s-1VARIABLES\s0\fR) and sqsh is in interactive mode, then the current history buffer is written to \&\fB\f(CB$HOME\fB\fR/.sqsh_history when you exit. This file is then read back into sqsh the next time it is started in interactive mode. .PP \&\fBNamed Buffers\fR: At any time during a session the \fBWork Buffer\fR, or any of the \&\fBHistory Buffers\fR may be copied into a named buffer using the \fB\ebuf\-copy\fR command (see section \fB\s-1COMMANDS\s0\fR, below). These buffers are lost when you exit (however you may use the \fB\ebuf\-save\fR command to save named buffers to a file). .PP \fIBuffer Short-Hand\fR .IX Subsection "Buffer Short-Hand" .PP Many commands allow all of these buffers to be referenced in a short-hand fashion, very similar to the way that \fB\f(BIcsh\fB\|(1)\fR references its commands history. Any of these shorthands may be used for any \fIbuffer\fR parameter described in the \&\fB\s-1COMMANDS\s0\fR section: .IP "!." 4 The current work buffer. .IP "!!" 4 The last command executed (note, this is not available in non-interactive mode as it does not maintain a history). .IP "!+" 4 The next available history entry. This is a write-only buffer, so typically only applies to such commands as \fB\ebuf\-copy\fR. .IP "!n" 4 .IX Item "!n" Refers to history #n. Each time an entry is written to history it is assigned an increasing number from the last entry, with this short-hand you may reference any given history. .IP "!buf_name" 4 .IX Item "!buf_name" Just for consistency this is supplied as a reference to named buffer \&\fIbuf_name\fR, however \fIbuf_name\fR without the leading '!' is also considered correct. .IP "buf_name" 4 .IX Item "buf_name" Refers to the named buffer \fIbuf_name\fR. .PP \fIVariables\fR .IX Subsection "Variables" .PP Variables may also be contained within work buffers. Under these circumstances the variables remain unexpanded until the buffer is sent to the database (via the \fB\ego\fR command), during which time they are expanded and replaced within the buffer. This behavior may be altered via the \fB\f(CB$expand\fB\fR variable. (see \fBSpecial Variables\fR, below). .PP The following is an example of using variables within a buffer: .PP .Vb 3 \& 1> \eset table_name=syscolumns \& 1> select count(*) from $table_name \& 2> \ego .Ve .PP This is the equivalent of performing the query: .PP .Vb 2 \& 1> select count(*) from syscolumns \& 2> \ego .Ve .PP directly. Typically this feature is useful for reusing large complex \fBwhere\fR clauses, or long column names. .PP Quoting rules apply the same in \s-1SQL\s0 buffers as they do in command lines. That is, any variables contained within double quotes (") are expanded and variables contained within single quotes (') are left untouched. Thus: .PP .Vb 2 \& 1> select "$username", \*(Aq$username\*(Aq \& 2> \ego .Ve .PP yields the results .PP .Vb 2 \& \-\-\-\- \-\-\-\-\-\-\-\-\- \& gray $username .Ve .PP \fICommand Substitution\fR .IX Subsection "Command Substitution" .PP As with the command line, the output of \s-1UNIX\s0 commands may also be substituted within a \s-1SQL\s0 buffer upon execution (once again, only if the \fB\f(CB$expand\fB\fR variable is set to 1, or true). In this circumstance the command contained within back quotes (`) is replaced with its output prior to forwarding the buffer to \s-1SQL\s0 server. For example: .PP .Vb 2 \& 1> select count(*) from \`echo syscolumns\` \& 2> \ego .Ve .PP Causes the strings 'echo syscolumns' to be replaced by the word \&\fIsyscolumns\fR prior to executing the command. It should be noted that the contents of the substituted command are only executed at the time of the \fB\ego\fR command, not when the line of \s-1SQL\s0 is input. .SS "Flow-of-Control" .IX Subsection "Flow-of-Control" New with version 2.0 of sqsh, is the ability to perform basic flow-of-control and functions using the \fB\eif\fR, \fB\ewhile\fR, \fB\edo\fR, and \fB\efunc\fR commands. .PP \fIBlocks & \s-1SQL\s0 Buffers\fR .IX Subsection "Blocks & SQL Buffers" .PP All sqsh flow-of-control commands are block-based. That is, if the test expression of the command is met, then a block of sqsh-script will be executed. For example, the definition of the \fB\eif\fR command is: .PP .Vb 3 \& \eif expression \& block \& \efi .Ve .PP This \fIblock\fR may be any number of lines of sqsh commands, \s-1SQL\s0, or flow-of-control statements to be executed if the \fIexpression\fR evaluates to a success condition (0). .PP Each \fIblock\fR has its own \s-1SQL\s0 buffer for the duration that the \fIblock\fR is executed. That is, the following statements: .PP .Vb 10 \& 1> /* \& 2> ** IMPROPER USAGE OF IF BLOCK \& 3> */ \& 4> select count(*) from \& 5> \eif [ $x \-gt 10 ] \& 6> sysobjects \& 7> \eelse \& 8> sysindexes \& 9> \efi \& 5> go .Ve .PP will yield: .PP .Vb 3 \& Msg 102, Level 15, State 1 \& Server \*(Aqbps_pro\*(Aq, Line 1 \& Incorrect syntax near \*(Aqfrom\*(Aq .Ve .PP because the string 'sysobjects' or 'sysindexes' were inserted into their own \s-1SQL\s0 buffers. These buffers are discarded as soon as the end of the block was reached, and since a \fB\ego\fR command was not contained within the block, no additional errors were generated. .PP Thus, the correct way to write the above expression would be: .PP .Vb 10 \& 1> /* \& 2> ** PROPER USAGE OF IF BLOCK \& 3> */ \& 4> \eif [ $x \-gt 10 ] \& 5> select count(*) from sysobjects \& 6> go \& 7> \eelse \& 8> select count(*) from sysindexes \& 9> go \& 10> \efi .Ve .PP or, even: .PP .Vb 10 \& 1> /* \& 2> ** PROPER USAGE OF IF BLOCK \& 3> */ \& 4> \eif [ $x \-gt 10 ] \& 5> \eset table_name=sysobjects \& 6> \eelse \& 7> \eset table_name=sysindexes \& 8> \efi \& 4> select * from $table_name \& 5> go .Ve .PP Also, note that the line number displayed in the sqsh prompt resets to the current position in the outer \s-1SQL\s0 buffer after reaching the \fB\efi\fR terminator. .PP \fIExpressions\fR .IX Subsection "Expressions" .PP All flow-of-control statements in sqsh take an \fIexpression\fR to determine which \&\fIblock\fR of code to execute. Just like \s-1UNIX\s0's Bourne Shell, this \fIexpression\fR is simply an operating system program that is executed by sqsh. If the command returns a success status (calls \fIexit\fR\|(0)), then it is considered successful. .PP For example, with following statement: .PP .Vb 3 \& \ewhile test $x \-lt 10 \& block \& \edone .Ve .PP will execute the contents of \fIblock\fR while the current value of \f(CW$x\fR is less than 10. Note that 'test' is a standard \s-1UNIX\s0 program to perform basic string or numeric comparisons (among other things). Also, unlike many shells, sqsh has no built-in version of 'test'. .PP Sqsh does, however, support the standard short form of 'test': .PP .Vb 3 \& \ewhile [ $x \-lt 10 ] \& block \& \edone .Ve .PP With this expression the open brace ('[') is replaced by the sqsh parser with 'test', and the close brace (']') is discarded. .PP \fIUnsupported Expressions\fR .IX Subsection "Unsupported Expressions" .PP Currently sqsh does not support the standard shell predicate operators '&&' and '||'. These can be performed like so: .PP .Vb 3 \& \eif sh \-c "cmd1 && cmd2" \& block \& \edone .Ve .PP \eif statement .IX Subsection "if statement" .PP The \fB\eif\fR command performs conditional execution of a sqsh \fIblock\fR based upon the outcome of a supplied expression: .PP .Vb 7 \& \eif expr1 \& block1 \& \eelif expr2 \& block2 \& \eelse \& block3 \& \efi .Ve .PP In this example, if expression \fIexpr1\fR evaluates to true, then the block \&\fIblock1\fR is evaluated. Otherwise, if the expression \fIexpr2\fR evaluates to true, then block \fIblock2\fR is evaluated. Finally, if all other tests fail \fIblock3\fR is evaluated. .PP Note that, unlike Bourne Shell, every \fB\eif\fR command must be accompanies by a trailing \fB\efi\fR statement. Also the sqsh parser is not terribly intelligent: The \&\fB\eelse\fR and \fB\efi\fR statements must be the only contents on the line in which they appear, and they may not be aliased to another name. .PP \ewhile statement .IX Subsection "while statement" .PP The \fB\ewhile\fR command executes a \fIblock\fR of sqsh code for the while a supplied expression remains true. .PP .Vb 3 \& \ewhile expr \& block \& \edone .Ve .PP In this example, while the expression \fIexpr\fR evaluates to true, then the block \&\fIblock\fR is evaluated. .PP The \fB\ebreak\fR statement may be used to break out of the inner-most \fB\ewhile\fR or \&\fB\efor\fR loop (more on \fB\efor\fR below). .PP \efor statement .IX Subsection "for statement" .PP The \fB\efor\fR command executes a \fIblock\fR of sqsh code for each \fIword\fR supplied: .PP .Vb 3 \& \efor var in word ... \& block \& \edone .Ve .PP For each \fIword\fR supplied, the value of the variable \fB\f(CB$var\fB\fR is set to the word and the \fIblock\fR of code is executed. Execution ends when there are no more words in the list. .PP As with \fB\ewhile\fR the \fB\ebreak\fR statement may be used to break out of the inner-most execution loop. .PP \edo command .IX Subsection "do command" .PP The \fB\edo\fR command is kind of a cross between a statement and a command. .PP It is a form of \fB\ego\fR (see below for details on the \fB\ego\fR command) in which a \&\fIblock\fR of sqsh code may be executed for each row of data returned from the query. When the \fIblock\fR is executed, special sqsh variables #[0\-9]+ (a hash followed by a number) may be used to reference the values in the returned query. For example the following command: .PP .Vb 8 \& select dbid, name from master..sysdatabases \& \edo \& \eecho "Checkpointing database #2, dbid #1" \& use #2 \& go \& checkpoint \& go \& \edone .Ve .PP would cause a \s-1CHECKPOINT\s0 command to be issued in each database on the server. .PP Command line options .IX Subsection "Command line options" .PP The \fB\edo\fR command establishes a new connection to be used by the \fIblock\fR of code when executed. By default, this connection is established to the current server (the current setting of \fB\f(CB$DSQUERY\fB\fR), using the current username (\fB\f(CB$username\fB\fR) and the current password (\fB\f(CB$password\fB\fR). This behavior may, however, be overridden using command line options: .IP "\-D database" 4 .IX Item "-D database" Establishes the connection to the database as the supplied \fIdatabase\fR. .IP "\-U username" 4 .IX Item "-U username" Establishes the connection to the server as the supplied \fIusername\fR. .IP "\-P password" 4 .IX Item "-P password" Establishes the connection to the server using the supplied \fIpassword\fR (which is hopefully a valid password for the supplied \fIusername\fR). .IP "\-S server | host:port[:filter]" 4 .IX Item "-S server | host:port[:filter]" Establishes the connection to the supplied \fIserver\fR. .IP "\-n" 4 .IX Item "-n" Do not create a connection for use by the \fB\edo\fR loop. This flag is mutually exclusive with the above flags. With this flag enabled, attempts to perform database commands within the \fIblock\fR will generate a flurry of CT-Library errors. .PP Column variables .IX Subsection "Column variables" .PP As mentioned above, the values of the columns in the current result set may be determined using the special #[0\-9]+ variables. Thus, the variable #1 would contain the value of column number one of the current result set, and #122 could contain the value of the 122'nd column (column numbers begin at 1). .PP In the case of nested \fB\edo\fR loops, values in previous nesting levels may be referred to by simply appending an addition '#' for each previous nesting level, like so: .PP .Vb 7 \& select id, name from sysobjects \& \edo \& select name, indid from sysindexes where id = #1 \& \edo \& \eecho "Table ##2 (objid ##1) has index #1" \& \edone \& \edone .Ve .PP obviously, this isn't the way you would do this query in real life, but you get the idea. .PP When expanding columns with \s-1NULL\s0 values, the column variable will expand to an empty string (''). Also, references to non-existent columns, such as #0, will result in an empty string (''). .PP As with regular sqsh variables (those referenced with a '$'), column variables will not be expanded when contained within single quotes. .PP Aborting .IX Subsection "Aborting" .PP If the \fB\ebreak\fR or \fB\ereturn\fR commands are issued during the processing of a \&\fB\edo\fR loop, the current query will be canceled, the connection used by the loop will be closed (unless the \fB\-n\fR flag was supplied) and the \fB\edo\fR loop will abort. .PP \efunc command .IX Subsection "func command" .PP The \fB\efunc\fR command is used to define a reusable block of sqsh code as a function. Functions are defined like so: .PP .Vb 9 \& \efunc stats \& \eif [ $# \-ne 1 ] \& \eecho "use: stats [on | off]" \& \ereturn 1 \& \efi \& set statistics io ${1} \& set statistics time ${1} \& go \& \edone .Ve .PP In this example a new function is established called \fIstats\fR that expects a single argument, either \*(L"on\*(R" or \*(L"off\*(R". Using this argument, \fIstats\fR will enable or disable time-based and I/O\-based statistics. .PP Once established, the function may be called like so: .PP .Vb 1 \& \ecall stats on .Ve .PP Causing all instances of ${1} to be replaced with the first command line argument to \fIstats\fR. .PP Command line options .IX Subsection "Command line options" .PP Currently only one command line argument is available to the \fB\efunc\fR command. .IP "\-x" 4 .IX Item "-x" Causes the function to be exported as a \fIsqsh\fR command. That is, the function may be invoked directly without requiring the \fB\ecall\fR command. This behavior is optional because command names can potentially conflict with T\-SQL keywords. When using this flag it is recommended that you prepend a backslash (\e) to your function name. .PP Function variables .IX Subsection "Function variables" .PP As shown in the example above, several special variables are available for use within the body of the function. These are: .IP "$#" 4 Expands to the number of arguments supplied to the function or script when invoked. .IP "$*" 4 Expands to the complete list of arguments supplied to the function or script when invoked. .IP "${0}..${N}" 4 .IX Item "${0}..${N}" Expands to positional arguments to the function. ${0} is the name of the function or the script file being invoked, ${1} is the first argument, ${2} the second and so-on, up to argument \fIN\fR. Note that, unlike most shells, sqsh requires that function arguments be referred to using the special curly brace syntax (${1}, rather than \f(CW$1\fR). The reason for this is that \f(CW$1\fR is a valid \&\s-1MONEY\s0 value and using the curly braces gets rid of this ambiguity. .IP "$?" 4 After the invocation of a function, this will contain its return value (see below). .PP Return value .IX Subsection "Return value" .PP A value may be returned from a function via the \fB\ereturn\fR command. .PP Like so: .PP .Vb 1 \& \ereturn N .Ve .PP Where \fIN\fR is a positive value. This return value is available to the caller of the function via the \fB$?\fR variable. As convention, a return value of 0 is used to indicate a success. .PP If \fB\ereturn\fR is not explicitly called, the default return value is the current value of the \fB$?\fR variable (which is set to 0 upon entry of the function). Thus, if any \s-1SQL\s0 statements are invoked within the function, the default return value of \fB$?\fR will be the last error code returned during the processing of the \&\s-1SQL\s0 statement. .SS "Kerberos Support" .IX Subsection "Kerberos Support" Starting with version 2.1.6, \fIsqsh\fR provides the same command line options as \&\fIisql\fR to handle Kerberos network authentication. .PP In version 2.1.5 experimental Kerberos support was added using the \-K and \-R options. \-K was merely a switch to set Kerberos on. In sqsh 2.1.6 a more advanced implementation of network authentication is introduced, although still experimental. .PP By using the parameters \-K, \-R, \-V, \-Z you can make use of your defined network security settings (libtcl.cfg). The named options are identical to the ones defined for \fIisql\fR. .IP "\-K keytab_file" 4 .IX Item "-K keytab_file" Keytab_file name for \s-1DCE\s0. .IP "\-R server_principal" 4 .IX Item "-R server_principal" Server principal name when servername specified in interfaces differs from the real server name. .IP "\-V [bcdimoqru]" 4 .IX Item "-V [bcdimoqru]" Specify security options to use with the security mechanism. Each character stands for a specific security service. .IP "\-Z [secmech|default|none]" 4 .IX Item "-Z [secmech|default|none]" Request a security mechanism defined for Kerberos, \s-1DCE\s0 or \s-1PAM\s0 in your libtcl.cfg file. Use \fBsecmech\fR to specify the name of a \s-1SECURITY\s0 entry or \&\fBdefault\fR for the first available entry in libtcl.cfg. \fBNone\fR must be specified to disable network authentication or reset possible existing values in variables \fB\f(CB$secmech\fB\fR or \fB\f(CB$secure_options\fB\fR. .PP For example, connecting to a server using Kerberos (which happens to be the default, i.e. first entry in libtcl.cfg [\s-1SECURITY\s0] tab in this example): .PP .Vb 9 \& ~$ sqsh \-SSYB1502 \-Uuser1 \-RFC6A1502 \-Z \& \econnect: Network authenticated session expires at: \& 16 Feb 2010 15:28:39 (11764 secs) \& SYB1502.user1.master.1> select @@servername,@@authmech, \& show_sec_services(); \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \-\-\-\-\-\-\-\-\-\-\- \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \& FC6A1502 kerberos unifiedlogin delegation mutualauth \& integrity confidentiality \& detectreplay detectseq .Ve .PP Note that the real name of the server (@@servername) differs from the server name in the interfaces file, so we have to specify the principal name through the \fB\-R\fR parameter. When you do not specify the \fB\-V\fR parameter together with \fB\-Z\fR, all available security options will be enabled. When \fB\-V\fR is specified without any security service options, only option \fBu\fR for Network Authentication will be implicitly set and the default security mechanism will be used if \fB\-Z\fR is not specified. .PP .Vb 10 \& [user1@linux\-fc6a ~]$ sqsh \-SFC6A1502 \-Uuser1 \-V \& Open Client Message \& Layer 7, Origin 9, Severity 5, Number 1 \& ct_connect(): security service layer: internal security control \& layer error: \& Security service provider internal error \-1765328352 \& occurred. \& [user1@linux\-fc6a ~]$ kinit \& Password for user1@LOCALDOMAIN: \& [user1@linux\-fc6a ~]$ sqsh \-SFC6A1502 \-Uuser1 \-V \& \econnect: Network authenticated session expires at: \& 16 Feb 2010 15:28:39 (10964 secs) \& FC6A1502.user1.master.1> .Ve .PP When the connection succeeds, \fIsqsh\fR will store the real name of the security mechanism in the variable \fB\f(CB$secmech\fB\fR. For example: \*(L"\eecho \f(CW$secmech\fR\*(R" may show \&\fIcsfkrb5\fR. The parameter \fB\-V\fR takes a list of characters from the possible values of \fIbcdimoqru\fR. The option \fBu\fR enables Network Authentication, is the default and will allways be set when using \fB\-V\fR or \fB\-Z\fR, specified or not. .PP .Vb 10 \& b \- chanbinding : Channel binding \& c \- confidentiality : Data confidentiality service \& d \- delegation : Allow delegated credentials \& i \- integrity : Data integrity service \& m \- mutualauth : Mutual authentication for connection \& establishment \& o \- dataorigin : Data origin stamping service \& q \- detectseq : Out\-of\-sequence detection \& r \- detectreplay : Data replay detection \& u \- unifiedlogin : Network Authentication .Ve .PP Please check master.dbo.syssecmechs for available services. Non-existing or not supported services supplied with \fB\-V\fR are silently ignored. If you specify \&\fB\-V\fR and/or \fB\-Z\fR, \fIsqsh\fR assumes network authentication is tried and no password is required. .PP If you have a network authenticated connection and want to \ereconnect using normal \s-1ASE\s0 authentication with username and password, you have to reset the network authentication variables by specifying \-Znone .PP For example: .PP .Vb 10 \& [user1@linux\-fc6a ~]$ sqsh \-SFC6A1502 \-Uuser1 \-V \& \econnect: Network authenticated session expires at: \& 16 Feb 2010 15:28:39 (10764 secs) \& FC6A1502.user1.master.1> \eecho $secmech csfkrb5 \& FC6A1502.user1.master.1> \ereconnect \-SASE1502 \-Usa \-Psybase \& Open Client Message \& Layer 7, Origin 9, Severity 5, Number 8 \& ct_connect(): security service layer: internal security control \& layer error: \& Consistency checks performed on the credential failed \& (minor status 0). \& FC6A1502.user1.master.1> \ereconnect \-SASE1502 \-Usa \-Psybase \-Znone \& ASE1502.sa.master.1> .Ve .PP The first \ereconnect fails because sqsh still wants to try network authentication. However, no user principal for 'sa' exists and no ticket is set and thus the connection fails. The second \fB\ereconnect\fR succeeds as the \-Znone option reset appropriate variables. If the Kerberos ticket is renewed with \fBkinit\fR or any other client tool, the \&\fIsqsh\fR session must perform a \fB\ereconnect\fR to refresh the credentials and to prevent a premature session abort. With the command \fB\esnace\fR you can request for the session expiration interval. Depending on the security services that are set, the database connection may be closed without warning as soon as the ticket expires. .PP See chapter 16 \*(L"External Authentication\*(R" from the Sybase System Administration Guide volume 1 for more information on Kerberos network authenticationi, e.a. .SH "COMMANDS" .IX Header "COMMANDS" .SS "Read-Eval-Print" .IX Subsection "Read-Eval-Print" The read-eval-print loop is the heart of the sqsh system and is responsible for prompting a user for input and determining what should be done with it. Typically this loop is for internal use only, however they are open to the user because there are some creative things that can be done with them. .IP "\eloop [\-i] [\-n] [\-e sql] [file]" 4 .IX Item "loop [-i] [-n] [-e sql] [file]" The \fB\eloop\fR command reads input either from a file, a supplied \s-1SQL\s0 statement, or from a user (see the options below), determining whether the current line is a portion of a T\-SQL statement or a sqsh command, and performing the appropriate action. When run in an interactive mode \fB\eloop\fR is also responsible for displaying the current prompt (see \fB\f(CB$prompt\fB\fR below). .Sp \&\fB\eloop\fR completes when all input has been depleted (end-of-file is encountered) or when a command, such as \fB\eexit\fR requests that \fB\eloop\fR exit. .RS 4 .IP "\-i" 4 .IX Item "-i" Normally, if \fIfile\fR is supplied and does not exist, \fB\eloop\fR will return with an error condition, usually causing sqsh to exit. By supplying the \fB\-i\fR flag, control will be returned to the calling loop as if end-of-file had been reached (that is, with no error condition). .IP "\-n" 4 .IX Item "-n" By default, \fB\eloop\fR will automatically attempt to connect to the database if a connection has not already been established via the \fB\econnect\fR command. The \&\fB\-n\fR flag disables this behavior allowing \fB\eloop\fR to process commands that do not require database support. .IP "\-e sql" 4 .IX Item "-e sql" Causes \fB\eloop\fR to process the contents of \fIsql\fR as if the user had typed it at the prompt and an implicit call to \fB\ego\fR is automatically appended to the statement. If multiple instances of \fB\-e\fR are supplied, they are all sent as a single batch to the \s-1SQL\s0 Server for processing. This option may not be used in combination with a \fIfile\fR name as well. .IP "file" 4 .IX Item "file" Specifies the name of a \fIfile\fR to be used as input rather than reading input from the user or from the \fB\-e\fR flag. .RE .RS 4 .RE .PP \fIDatabase Access\fR .IX Subsection "Database Access" .PP Given the size and complexity of sqsh (just look at the length of this man page), it is amazing how few database manipulation commands that there actually are. The following are commands that affect or use the current database connection: .IP "\econnect [\-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]]" 4 .IX 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]]" This command is used primarily for internal use to establish a connection to a database. If a connection is already established it has no effect, however if a connection has not been established and \fB\f(CB$password\fB\fR has not been supplied, then the password is requested and a connection is established. \fB\econnect\fR accepts the following parameters: .RS 4 .IP "\-A" 4 .IX Item "-A" Specifies the size of the network \s-1TDS\s0 packets used to communicate with the \s-1SQL\s0 server. This value must be between 512 and 8192, and be a multiple of 512. Check your \s-1SQL\s0 Server configuration to determine supported packet sizes. This value may also be specified at run-time using the \f(CW$packet_size\fR variable. .IP "\-c" 4 .IX Item "-c" By default, the \fB\econnect\fR command uses the contents of \fB\f(CB$database\fB\fR to determine the database context that should be used upon establishing the connection (this is used by \fB\ereconnect\fR to preserve the current database context upon reconnection). The \fB\-c\fR flag suppresses this behavior and the default database context of login is used instead. .IP "\-D db" 4 .IX Item "-D db" Causes \fB\econnect\fR to attempt to automatically switch the database context to \&\fIdb\fR after establishing the connection. .Sp Using this flag is identical to setting the \fB\f(CB$database\fB\fR variable prior to establishing the connection. .IP "\-G tds version" 4 .IX Item "-G tds version" Set the \s-1TDS\s0 version to use. See the global startup parameter \-G for more information on \s-1TDS\s0 version. .IP "\-S srv | host:port[:filter]" 4 .IX Item "-S srv | host:port[:filter]" The name or address of the Sybase \fIserver\fR to connect, this defaults to \&\fB\f(CB$DSQUERY\fB\fR if not supplied. .IP "\-U user" 4 .IX Item "-U user" The Sybase \fIuser\fR to connect to the database as, this defaults to \fB\f(CB$username\fB\fR variable if not supplied. .IP "\-P pass" 4 .IX Item "-P pass" The \fIpassword\fR for \fIuser\fR required to connect to \fIserver\fR. This defaults to \&\fB\f(CB$password\fB\fR if not supplied. .IP "\-I ifile" 4 .IX Item "-I ifile" The full path of an alternate Sybase \fIinterfaces\fR file to use. .IP "\-J charset" 4 .IX Item "-J charset" The name of the client character set to communicate with the server. .IP "\-K keytab_file" 4 .IX Item "-K keytab_file" Used for \s-1DCE\s0 user authentication. .IP "\-R principal_name" 4 .IX Item "-R principal_name" Use for Kerberos user authentication to specify the name of the server principal when the name differs from the \fB\f(CB$DSQUERY\fB\fR value. .Sp See also the discussion on Kerberos support. .IP "\-n" 4 .IX Item "-n" Specifies that the connection must use \s-1ANSI\s0 compliant chained mode. .IP "\-N appname" 4 .IX Item "-N appname" Specify the application name the server will use for program_name in the sysprocesses table. .IP "\-Q query_timeout" 4 .IX Item "-Q query_timeout" Set a query timeout period in seconds. .IP "\-T login_timeout" 4 .IX Item "-T login_timeout" Specifies a maximum wait time for session setup. .IP "\-V [bcdimoqru]" 4 .IX Item "-V [bcdimoqru]" Security services used for Kerberos support and other security mechanisms. .IP "\-X" 4 .IX Item "-X" Initiates the login connection to the server with client-side password encryption (if supported). If either \s-1SQL\s0 Server does not recognize this option, or if the version of CT-Lib used to compile \fIsqsh\fR does not support this option, then it will be ignored. This option may also be set using the \&\fB\f(CB$encryption\fB\fR environment variable. .IP "\-z language" 4 .IX Item "-z language" Specifies an alternate language to display sqsh prompts and messages. Without the \-z flag, the server's default language will be used. This may also be set using the \f(CW$language\fR variable. .IP "\-Z [secmech|default|none]" 4 .IX Item "-Z [secmech|default|none]" Specifies the security mechanism to use for user authentication. For example csfkrb5 for Kerberos support. .RE .RS 4 .RE .IP "\ereconnect [\-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]]" 4 .IX 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]]" The \fB\ereconnect\fR command may be used to force a reconnection to the database using a new username, server name, or password (if desired). If this command fails, the current connection remains (if there is any), however if it succeeds then the current connection is closed and the new connection becomes the only active one. .Sp All arguments that are accepted by \fB\econnect\fR are also accepted by \&\fB\ereconnect\fR (in fact \fB\ereconnect\fR uses \fB\econnect\fR to establish the new connection). .IP "\erun" 4 .IX Item "run" This command will execute a script file like \fB\eloop\fR but the \fB\erun\fR command will allow optional script parameters. Furthermore the command accepts the following parameters. .RS 4 .IP "\-e" 4 .IX Item "-e" Run the script file with echo on. .IP "\-f" 4 .IX Item "-f" Suppress footers. .IP "\-h" 4 .IX Item "-h" Suppress headers. .IP "\-l" 4 .IX Item "-l" Suppres separator lines with pretty output style. .IP "\-n" 4 .IX Item "-n" Disable \s-1SQL\s0 buffer variable expansion. .IP "\-p" 4 .IX Item "-p" Report runtime statistics. .IP "\-m style" 4 .IX Item "-m style" Specify output style {bcp|csv|horiz|html|meta|none|pretty|vert}. .IP "\-i filename" 4 .IX Item "-i filename" Required parameter to specify a filename to be run by \fIsqsh\fR. .RE .RS 4 .Sp For example: \fB\erun \-p \-i ~/tmp/runtst.sqsh 10 \-m pretty\fR .RE .IP "\elcd dirname" 4 .IX Item "lcd dirname" Local Change Directory. This command takes a directory name as argument and changes the local \s-1SQSH\s0 context to this directory. You can use \fB\elcd \-\fR to return back to the previous directory. If you exit \fIsqsh\fR then the shell is still in the same directory from where sqsh was started. .IP "\epwd" 4 .IX Item "pwd" Print Working Directory. Show the name of the current local working directory. .IP "\els" 4 .IX Item "ls" List files in the current directory. Does not take any arguments and is basically a shortcut for \fB\eshell ls\fR. .IP "\esnace" 4 .IX Item "snace" Will show the session expiration interval for a network authenticated session, like in a Kerberos enabled session, for example. .IP "\ego [options] [xacts]" 4 .IX Item "go [options] [xacts]" Sends the contents of the \fBWork Buffer\fR to the database, establishing a new connection to the database if one does not already exist (by calling the \&\fB\econnect\fR above). It them displays the results of the query back to stdout and returns, causing the \fBWork Buffer\fR to be cleared and moved to the end of the \&\fBHistory Buffer\fR. .Sp If the \fBWork Buffer\fR is empty and the \fB\f(CB$repeat_batch\fB\fR variable is set to \*(L"On\*(R", \&\fB\ego\fR will attempt to re-run the last command executed (this will only work in interactive mode if history support is enabled). .Sp \&\fB\ego\fR accepts the following arguments: .RS 4 .IP "\-d display" 4 .IX Item "-d display" If X11 support is compiled into sqsh, and X display mode is being used (see \&\fB\-x\fR, below), then \fIdisplay\fR will be used as the X display area for the result set. By default the environment variable \fB\f(CB$DISPLAY\fB\fR is assumed. .IP "\-e" 4 .IX Item "-e" Echo the expanded \s-1SQL\s0 buffer before sending it to the server. .IP "\-f" 4 .IX Item "-f" Turns off the display of the footer message \*(L"(%d rows affected)\*(R". Footer messages may also be turned off via the \fB\f(CB$footers\fB\fR variable. .IP "\-h" 4 .IX Item "-h" Turns off all column headers. These may also be turned off via the \fB\f(CB$headers\fB\fR variable. .IP "\-m style" 4 .IX Item "-m style" Temporarily changes the display style to \fIstyle\fR for the duration of the command. Currently supported styles are \fBhoriz\fR (or \fBhor\fR or \fBhorizontal\fR), \&\fBvert\fR (or \fBvertical\fR), \fBbcp\fR, \fBcsv\fR, \fBhtml\fR, \fBmeta\fR, \fBpretty\fR and \&\fBnone\fR. The display style may be permanently set via the \fB\f(CB$style\fB\fR variable or the \fB\-m\fR command line flag. .IP "\-l" 4 .IX Item "-l" Suppress separator lines when using the \fB\-m pretty\fR output style. May also be turned off via the \fB\f(CB$nosepline\fB\fR variable. .IP "\-n" 4 .IX Item "-n" Turns off variable expansion in the \fBWork Buffer\fR prior to sending it to the server, this may also be turned off via the \fB\f(CB$expand\fB\fR variable. .IP "\-p" 4 .IX Item "-p" Turns on output of performance statistics when the result set has been successfully returned from the server. This may also be turned on via the \fB\-p\fR command line argument to sqsh, or the \fB\f(CB$statistics\fB\fR variable. .IP "\-s sec" 4 .IX Item "-s sec" If the value of \fIxacts\fR is greater than 1, this causes sqsh to sleep for \fIsec\fR seconds before executing the next transaction. Note that the time spent sleeping is excluded from the statistical information displayed with the \fB\-p\fR flag. .IP "\-t [filter]" 4 .IX Item "-t [filter]" Filters the command batch through an external program, \fIfilter\fR, and prior to being sent to the \s-1SQL\s0 Server. If \fIfilter\fR is not supplied, then \fB\f(CB$filter_prog\fB\fR is used (default is 'm4 \-'). This value may also be set via the \fB\f(CB$filter\fB\fR and \&\fB\f(CB$filter_prog\fB\fR variables. .IP "\-w width" 4 .IX Item "-w width" Overrides the value of \fB\f(CB$width\fB\fR for the life of the query (see \fB\f(CB$width\fB\fR below). .IP "\-x [xgeom]" 4 .IX Item "-x [xgeom]" Turns on the X11 display filter (only if X11 support is compiled into sqsh), which causes the result set to be sent to a separate window. If \fIxgeom\fR is supplied, then this value will be used as \fB\f(CB$xgeom\fB\fR for the life of the query (see \fB\f(CB$xgeom\fB\fR below). .IP "\-T xwin_title" 4 .IX Item "-T xwin_title" Specify the title name of the X result window to create. This will temporarily override the value of \fB\f(CB$xwin_title\fB\fR. Only useful to specify \-T in conjunction with \fB\-x\fR. .IP "xacts" 4 .IX Item "xacts" Specifies number of times the contents of the \fBWork Buffer\fR should be executed. Note that, similar to isql, a result set will only be displayed during the final execution of the batch. Also, the contents of the \fBWork Buffer\fR are only expanded once, prior to the first execution, so the contents of the buffer will not change between subsequent executions. .RE .RS 4 .RE .IP "\ebcp [bcp_options] table[:slicenumber|:partition name]" 4 .IX Item "bcp [bcp_options] table[:slicenumber|:partition name]" The \fB\ebcp\fR commands acts as a sort of enhanced \fB\ego\fR command that redirects the result set(s) of the batch to another server via the bcp protocol. While it is possible to \fB\ebcp\fR the result set back to the current server (the \&\fB\f(CB$DSQUERY\fB\fR variable), this is achieved more easily via a \s-1SELECT\s0 \s-1INTO\s0. .Sp The nitty-gritty details of \fB\ebcp\fR go like this: First the current \s-1SQL\s0 batch is expanded (unless the \fB\f(CB$expand\fB\fR variable is set to 0) and shipped off to the database for processing. If all goes well, a new connection is established to the destination database (as specified via \fB\f(CB$DSQUERY\fB\fR or the \fB\-S\fR flag) to transfer the result set using bcp. Then, the output of the source database connection is bound to the new bcp connection and data transfer is performed. \&\fB\ebcp\fR can handle multiple result sets without any problem (including result sets returned from stored procedures, etc.) provided that all of the result sets are valid for the destination table. .Sp The equivalent of a \*(L"bcp out\*(R" may be performed using the \fBbcp\fR display style setting and file redirection (see the \fB\f(CB$style\fB\fR variable). .RS 4 .IP "\-A packet" 4 .IX Item "-A packet" Specifies the \s-1TDS\s0 packet size used to communicate with the destination server. If not supplied this defaults to the value the \fB\f(CB$packet_size\fB\fR variable, or (if that is not set), the default server packet size (usually 512 bytes). .IP "\-b batch_size" 4 .IX Item "-b batch_size" The number of records transferred in a single transaction between servers. Note that reaching the end of a result causes the batch to be transferred, regardless of the value of \fIbatch_size\fR. The default is the entire result set. .ie n .IP "\-i """"" 4 .el .IP "\-i ``''" 4 .IX Item "-i " Using the \fI\-i\fR parameter you can send a \s-1SQL\s0 command to the target server that will be executed just before the bulk copy operation is started. This is useful if you need to truncate the target table first. For example: .Sp .Vb 2 \& 1> select * from proddb..materials \& 2> \ebcp \-SDTA \-i "truncate table testdb..materials" \-N \-X testdb..materials .Ve .IP "\-I ifile" 4 .IX Item "-I ifile" The full path of an alternate Sybase \fIinterfaces\fR file to use. .IP "\-J charset" 4 .IX Item "-J charset" Specifies the default \fIcharset\fR used to communicate with the \s-1SQL\s0 Server. This defaults to the current character set (the value of the \fB\f(CB$charset\fB\fR variable). .IP "\-m maxerr" 4 .IX Item "-m maxerr" The maximum number of batches that may fail before \fB\ebcp\fR gives up the ghost (default is 10). Note that this only refers to failures within a given batch. When performing a bcp of multiple result sets to a server, if a given result set has, say, too many columns or bad data types, then the entire bcp process is aborted regardless of the value of \fImaxerr\fR. .IP "\-N" 4 .IX Item "-N" Indicates that the value for an identity column in the destination table is being supplied within the result set. .IP "\-P password" 4 .IX Item "-P password" The \fIpassword\fR for \fIuser\fR required to connect to \fIserver\fR. This defaults to \&\fB\f(CB$password\fB\fR if not supplied. .IP "\-S server | host:port[:filter]" 4 .IX Item "-S server | host:port[:filter]" The name or address of the Sybase \fIserver\fR to connect, this defaults to \&\fB\f(CB$DSQUERY\fB\fR if not supplied. .IP "\-T" 4 .IX Item "-T" Transfer the data in transit without performing character set conversion at the client side. .IP "\-U user" 4 .IX Item "-U user" The Sybase \fIuser\fR to connect to the database as, this defaults to \fB\f(CB$username\fB\fR variable if not supplied. .IP "\-X" 4 .IX Item "-X" Causes password negotiation with the destination server to be performed using client-side encryption. .IP "\-z language" 4 .IX Item "-z language" Specifies the language setting to use. .IP "table[:slicenumber|:partition name]" 4 .IX Item "table[:slicenumber|:partition name]" As with regular \fBbcp\fR, \fItable\fR may be either a fully or partially specified table name in the destination server. Note that since a new database connection is established during the bcp processes that the database context of the connection may not be the same as the current context, so it is usually safest to fully specify the table name in the form database.owner.table. For partitioned tables you may supply a slicenumber or a partition name (separate table name and partition with a colon (:)) to bcp the data into the specified partition. .RE .RS 4 .RE .IP "\erpc [rpc_opt] rpc_name [[parm_opt] [@var=]value ...]" 4 .IX Item "rpc [rpc_opt] rpc_name [[parm_opt] [@var=]value ...]" The \fB\erpc\fR command is used to directly invoke a stored procedure call in the connected server. This command is particularly useful for communicating with an Open Server that does not directly support language calls. .Sp \&\fB\erpc\fR invokes the remote procedure \fIrpc_name\fR with one or more parameters that may be named (using \fI\f(CI@var\fI\fR) or anonymous (by not supplying a name). Unfortunately, due to the fact that Sybase's implementation of \s-1RPC\s0's, does not directly support most implicit data type conversions (mainly between \s-1VARCHAR\s0 (the string you supply on the command line) and the most other data types (that the remote procedure is expecting), the syntax for the \fB\erpc\fR command is somewhat complex. However, in short here is how things work: .Sp As the \fB\erpc\fR command line is being parsed, \fIsqsh\fR attempts to guess the data type of the parameter \fIvalue\fR based on the format (for example if it contains only digits, it is assumed to be an integer), \fIsqsh\fR then performs an explicit data type conversion prior to calling the remote procedure call. If \fIsqsh\fR guesses wrong, several flags are supplied to force it to perform the correct data type conversion (see \fBparm_opt\fR). .PP \fIDisplay Options\fR .IX Subsection "Display Options" .PP The following options may be supplied anywhere on the command line and are used to affect the manner in which the result set(s) returning from the remote procedure call are displayed: .IP "\-d display" 4 .IX Item "-d display" If X support is compiled into sqsh, the value of \fIdisplay\fR is used as the X windows \s-1DISPLAY\s0 variable. Note, this is usually supplied with the \fB\-x\fR flag, below. .IP "\-f" 4 .IX Item "-f" Turns off the display of the footer message \*(L"(%d rows affected)\*(R". Footer messages may also be turned off via the \fB\f(CB$footers\fB\fR variable. .IP "\-h" 4 .IX Item "-h" Turns off all column headers. These may also be turned off via the \fB\f(CB$headers\fB\fR variable. .IP "\-m style" 4 .IX Item "-m style" Temporarily changes the display style to \fIstyle\fR for the duration of the command. Currently supported styles are \fBhoriz\fR (or \fBhor\fR or \fBhorizontal\fR), \&\fBvert\fR (or \fBvertical\fR), \fBbcp\fR, \fBcsv\fR, \fBhtml\fR, \fBmeta\fR, \fBpretty\fR and \&\fBnone\fR. The display style may be permanently set via the \fB\f(CB$style\fB\fR variable or the \fB\-m\fR command line flag. .IP "\-r" 4 .IX Item "-r" Request to recompile the procedure prior to execution. .IP "\-w width" 4 .IX Item "-w width" Temporarily sets the output width to \fIwidth\fR. The output width may be permanently set via the \fI\f(CI$width\fI\fR variable. .IP "\-x [xgeom]" 4 .IX Item "-x [xgeom]" Sends output to a separate X window. If \fIxgeom\fR is supplied, then the X window uses this geometry (see \fB\f(CB$xgeom\fB\fR for details). .IP "\-T xwin_title" 4 .IX Item "-T xwin_title" Specify the title name of the X result window to create. This will temporarily override the value of \fB\f(CB$xwin_title\fB\fR. Only useful to specify \-T in conjunction with \fB\-x\fR. .PP \fIParameter Options\fR .IX Subsection "Parameter Options" .PP The following options may be supplied immediately prior to specifying a parameter \fIvalue\fR and are used to affect the way in which \fIsqsh\fR interprets the contents of the \fIvalue\fR prior to calling the remote procedure. Although \&\fIsqsh\fR will allow any combination of these parameters to be combined, it only really makes sense to combine the \fB\-x\fR flag with any other flag. .IP "\-b" 4 .IX Item "-b" Indicates that the \fIvalue\fR that is specified should be converted to \s-1VARBINARY\s0 before calling \fIrpc_name\fR. This flag is implicit (i.e. you need not supply it) if \fIvalue\fR starts with \*(L"0x\*(R" and contains only digits. .IP "\-c" 4 .IX Item "-c" Indicates that the \fIvalue\fR that is specified should be converted to \s-1VARCHAR\s0 prior to calling \fIrpc_name\fR. This flag is implicit if \fIvalue\fR does not match any of the implicit conversions for the other data types. .IP "\-d" 4 .IX Item "-d" Indicates that the \fIvalue\fR that is specified should be converted to double (float) before calling \fIrpc_name\fR. This flag is implicit if \fIvalue\fR is in valid floating point notation (e.g. 0.1, .1, 1.4e10, or 4e10). .IP "\-i" 4 .IX Item "-i" Indicates that the \fIvalue\fR that is specified should be converted to integer (int) before calling \fIrpc_name\fR. This flag is implicit if \fIvalue\fR contains only digits (and, optionally, a leading sign). .IP "\-y" 4 .IX Item "-y" Indicates that the \fIvalue\fR that is specified should be converted to money before calling \fIrpc_name\fR. This flag is implicit if \fIvalue\fR begins with a \*(L"$\*(R", and contains only digits and, optionally, a decimal. .IP "\-n" 4 .IX Item "-n" Indicates that the \fIvalue\fR that is specified should be converted to numeric before calling \fIrpc_name\fR. This flag is never implicit, as \fIvalue\fR would always match either int (\fB\-i\fR) or float (\fB\-d\fR); however, both of these types will implicitly be converted to a numeric as necessary by the procedure call. .IP "\-u" 4 .IX Item "-u" Indicates that \fIvalue\fR should be ignored and treated as a \s-1NULL\s0 value, This flag is implicit if \fIvalue\fR is "". .SS "Buffers" .IX Subsection "Buffers" The following commands may be used to create, destroy, or manipulate the various buffers described in the \fB\s-1BUFFERS\s0\fR section, above. .IP "\eclear" 4 .IX Item "clear" The \fB\eclear\fR command will discard the current buffer and in contradiction with the \fB\ereset\fR command, will not save the current buffer to the history. When sqsh is compiled with readline support, this command will also clear the screen. (as ^l does.) The alias \fBclear\fR is automatically established upon startup. .IP "\ehistory [\-i] [\-x count]" 4 .IX Item "history [-i] [-x count]" Displays the last \fB\f(CB$histsize\fB\fR batches that have either been sent to the database via the \fB\ego\fR command or cleared from the \fBWork Buffer\fR via the \&\fB\ereset\fR command. With option \fB\-i\fR also display the number of times the buffer is used and the last time the buffer was used. This information may be of special interest when using the \fB\f(CB$histunique\fB\fR feature. The \fB\-x\fR option may specify the number of most recent history entries to display instead of the total list of history entries. .IP "\ehist\-load [filename]" 4 .IX Item "hist-load [filename]" Load a history file and append items to the current history list. Use \fB\f(CB$history\fB\fR if no filename is specified as a parameter. .IP "\ehist\-save [filename]" 4 .IX Item "hist-save [filename]" Will save the current history buffers to the \fB\f(CB$history\fB\fR file or to the filename specified as a parameter. .IP "\eredraw" 4 .IX Item "redraw" Returns a request back to the current read-eval-print loop for it to redisplay the current \fBWork Buffer\fR. If run from non-interactive mode, this command has no effect. .IP "\ereset" 4 .IX Item "reset" The \fB\ereset\fR command corresponds directly to the \fIisql\fR 'reset' command, returning a request to the read-eval-print loop to clear the contents of the current \fBWork Buffer\fR and, if you are running in interactive mode, place a copy of the buffer into the \fBHistory Buffer\fR. The alias \fBreset\fR is automatically established upon startup of \fIsqsh\fR for backward compatibility with \fIisql\fR. .IP "\ebuf\-append dst-buffer [src\-buffer]" 4 .IX Item "buf-append dst-buffer [src-buffer]" Appends the contents of \fIsrc-buffer\fR (defaults to !.) to the contents of \&\fIdst-buffer\fR, if it exists. If \fIdst-buffer\fR doesn't exist it is created. .IP "\ebuf\-copy dst-buffer [src\-buffer]" 4 .IX Item "buf-copy dst-buffer [src-buffer]" Copies the contents of \fIsrc-buffer\fR (defaults to \fB!.\fR, the \fBWork Buffer\fR, if not supplied), to \fIdst-buffer\fR. Refer to \fB\s-1BUFFERS\s0\fR for information on buffer naming conventions. .IP "\ebuf\-del [buffer|range]" 4 .IX Item "buf-del [buffer|range]" Remove a history buffer from the history list. You can also specify a range list consisting of the first and last buffer numbers separated by a '\-'. For example: \&\*(L"\ebuf\-del 1\-10\*(R" will delete the first 10 history entries. Another example, \&\*(L"\ebuf\-del 21\*(R" will only delete buffer number 21. Note that the history buffers will be renumbered consecutively. .IP "\ebuf\-edit [\-r read\-buf] [\-w write\-buf]" 4 .IX Item "buf-edit [-r read-buf] [-w write-buf]" The \fB\ebuf\-edit\fR command is used to edit the contents of a buffer and place the changes into another buffer. This command may only be run while in interactive mode. If \fIread-buf\fR is not supplied then the buffer to be edited defaults to !., if it is not empty, otherwise it defaults to !!. If \fIwrite-buf\fR is not supplied then the edited buffer is written back to !.. .Sp By default, \fB\ebuf\-edit\fR uses the environment variable \fB\f(CB$EDITOR\fB\fR first, followed by \fB\f(CB$VISUAL\fB\fR to determine which editor to use, defaulting to 'vi' if the variable is not set. .Sp It is important to note that as of release 1.2, \fB\ebuf\-edit\fR is no longer able to use the name of an alias to it as the name of the editor to launch. This is primarily due to the change in the behavior of alias (see section \fBAliasing\fR, below, for details). .Sp The commands \fBedit vi\fR and \fBemacs\fR are automatically established upon startup of \fIsqsh\fR for backward compatibility with \fIisql\fR. .IP "\ebuf\-get buffer" 4 .IX Item "buf-get buffer" The \fB\ebuf\-get\fR command is supplied as a shorthand method of running \&\fB\ebuf\-copy\fR It is the equivalent of running: .Sp .Vb 1 \& \ebuf_append !. buffer .Ve .IP "\ebuf\-load [\-a] filename [dst\-buffer]" 4 .IX Item "buf-load [-a] filename [dst-buffer]" Copies the contents of \fIfilename\fR in \fIdst-buffer\fR (defaults to !.). If the \&\fB\-a\fR flag is supplied, the contents of \fIfilename\fR are appended to \&\fIdst-buffer\fR. Note that it is illegal to attempt to write to the contents of the history buffer. .IP "\ebuf\-save [\-a] filename [src\-buffer]" 4 .IX Item "buf-save [-a] filename [src-buffer]" Saves the contents of \fIsrc-buffer\fR (defaults to !.) to \fIfilename\fR. If the \&\fB\-a\fR flag is supplied the contents are appended to \fIfilename\fR rather than overwriting the current contents. .IP "\ebuf\-show [buffer]" 4 .IX Item "buf-show [buffer]" Displays the contents of the named \fIbuffer\fR. If \fIbuffer\fR is not supplied, then the contents of all named buffers are displayed. This command is slightly different from the commands above in that it is only legal to supply a \&\fBNamed Buffer\fR \fIbuffer\fR, \fBHistory Buffers\fR, and the \fBWork Buffer\fR will have no results. .SS "Variables" .IX Subsection "Variables" The following command(s) are used to manipulate the contents of internal variables and environment variables. .IP "\eset [\-x] [name=\fIvalue\fR ...]" 4 .IX Item "set [-x] [name=value ...]" If no arguments are supplied to \fB\eset\fR then the current values of all variables are displayed. Otherwise the variable \fIname\fR is set to \fIvalue\fR. Note that some internal variables (see \fB\s-1SPECIAL\s0 \s-1VARIABLES\s0\fR) may only be set with certain \&\fIvalue\fRs, so this action may fail, leaving the previous contents on \fIname\fR intact. The \fB\-x\fR flag causes the variable to be exported to the environment of any programs launched from \fIsqsh\fR. .SS "Job Control" .IX Subsection "Job Control" The following commands are used to view the status of, or manipulate background jobs that are currently running, these correspond roughly to the commands supplied by such shells as \fB\f(BIcsh\fB\|(1)\fR. .IP "\ejobs [\-i]" 4 .IX Item "jobs [-i]" Displays the status of any currently running jobs, including whether or not these jobs have pending output, how long they have been running, and when they were started. The \fB\-i\fR option will show some additional job information. Note that the total run time of the job is determined from the moment the job is marked complete by the read-eval-print loop when polled, not when it actually ended and is flagged as terminated by the signal handler. .IP "\ewait [job_id]" 4 .IX Item "wait [job_id]" Will pause until job designated by \fIjob_id\fR completes. If \fIjob_id\fR is a negative number then \fB\ewait\fR will pause until \fIany\fR pending jobs completes. If there are no jobs pending, or \fIjob_id\fR does not belong to a running job, then an error message is displayed. Note that if multiple jobs are running, and a \&\fB\ewait\fR is issued for one of them, the other jobs may not automatically get signaled when completed within the wait period of the specific job. The other jobs may need to get signaled with a \fB\ewait \-1\fR as well to be noticed complete by \fIsqsh\fR. .IP "\ekill job_id" 4 .IX Item "kill job_id" Terminates the job specified by \fIjob_id\fR, throwing away any output that may be deferred for the job. If \fIjob_id\fR is not a running job then an error message is displayed. .IP "\eshow job_id" 4 .IX Item "show job_id" Displays the deferred output of completed background job \fIjob_id\fR and removes the job from the list of pending jobs (removing the defer file in the process). If \fIjob_id\fR is still running, or is not a valid complete job, then an error message is displayed. You may need to issue a \fB\ewait job_id\fR first, to get notified of actual job completion. .SS "Aliasing" .IX Subsection "Aliasing" As of release 1.2, \fIsqsh\fR supports full \fIcsh\fR\-style command aliasing. With this feature, \fIsqsh\fR checks the first word of each line, \fIprior to any form of expansion\fR, to see if it matches the name of an existing alias. If it does, the command is reprocessed with the alias definition replacing its name. Unlike \&\fIcsh\fR, however, only one form of history substitution is available within an alias: the '\fB!*\fR' entry, indicating the current line being expanded. If no history expansion is called for, the arguments on the command line remain unchanged. .PP Like \fIcsh\fR, aliases are not recursively expanded, so it is perfectly legal to create an alias that expands to a command by the same name. .PP The following command is used to create an alias: .IP "\ealias [alias_name=alias_body]" 4 .IX Item "alias [alias_name=alias_body]" If no arguments are supplied to the \fB\ealias\fR command, then the list of aliases currently in effect is displayed. Otherwise, it creates a new alias with a name of \fIalias_name\fR and a body of \fIalias_body\fR; if \fIalias_name\fR already exists, the body of the existing \fIalias_name\fR is replaced with the new definition. .Sp After defining the new alias, whenever \fIsqsh\fR encounters a line beginning with \&\fIalias_name\fR, the remainder of the line is replaced with \fIalias_body\fR before any further processing is performed. .Sp If the string '\fB!*\fR' exists anywhere within \fIalias_body\fR, the arguments supplied to the alias are inserted at that point, otherwise the argument are appended to the end of the alias definition. For example: .Sp .Vb 3 \& 1> \ealias hi=\*(Aq\eecho !* said hello\*(Aq \& 1> hi Scott \& Scott said hello .Ve .Sp where as if the alias does not include the \fB!*\fR keyword, then it behaves like so: .Sp .Vb 3 \& 1> \ealias hi=\*(Aq\eecho said hello\*(Aq \& 1> hi Scott \& said hello Scott .Ve .Sp It is perfectly legal to include a \fB!*\fR more than once within a given \&\fIalias_body\fR. Currently there is no way to escape the string \fB!*\fR, if you really need this feature send me mail. .IP "\eunalias alias_name" 4 .IX Item "unalias alias_name" Removes \fIalias_name\fR. .SS "Miscellaneous" .IX Subsection "Miscellaneous" The left over commands. .IP "\eexit [x]" 4 .IX Item "exit [x]" The \fB\eexit\fR command requests that current read-eval-print loop cease processing. When the last loop returns, \fIsqsh\fR \fB\f(BIexit\fB\|(1)\fRs. You may specify a exit code as parameter which will be stored in \fB\f(CB$exit_value\fB\fR and will be used as return value to the shell upon exit of \fIsqsh\fR. (0 <= x <= 255). .IP "\eabort" 4 .IX Item "abort" Causes all nested read-eval-print loops to abort processing, causing \fIsqsh\fR to exit with an exit value of 254 (see section \fB\s-1EXIT\s0 \s-1STATUS\s0\fR). .IP "\eread [\-a] [\-n] [\-h] var_name [< filename]" 4 .IX Item "read [-a] [-n] [-h] var_name [< filename]" Reads a line of input from the user, placing the text of the line in the variable \fIvar_name\fR. If the \fB\-n\fR is used, then the trailing new-line is left on the line of text, and if \fB\-a\fR is supplied, then the text of the line is appended to the existing value of \fIvar_name\fR. The \fB\-h\fR flag turns off echoing of typed characters back to the user. It is also possible to read the contents of a file using the \fI\e<\fR file redirection notation. .IP "\esleep seconds" 4 .IX Item "sleep seconds" Causes \fIsqsh\fR too pause for \fIseconds\fR. This is useful within scripts of batches which need to pause briefly between batches (it was primarily useful to me for testing background jobs). .IP "\eecho [\-n] [args ...]" 4 .IX Item "echo [-n] [args ...]" Just like the \s-1UNIX\s0 \fB\f(BIecho\fB\|(1)\fR, this prints its arguments to stdout, followed by a new-line. If the \fB\-n\fR flag is supplied, the newline is omitted. .IP "\ewarranty" 4 .IX Item "warranty" Displays the standard \s-1GNU\s0 warranty. .IP "\ehelp [command]" 4 .IX Item "help [command]" Without any arguments \fB\ehelp\fR displays a brief list of all available commands, otherwise, it provides specific help for \fIcommand\fR, if available. When help is requested on a specific \fIcommand\fR, \fB\ehelp\fR looks for the file \&\fI\f(CI$help_dir\fI/command.hlp\fR and displays it to stdout. .IP "\eshell [shell command]" 4 .IX Item "shell [shell command]" If \fIshell command\fR is not supplied then \fIsqsh\fR executes \fB\f(CB$SHELL\fB\fR. If the \&\fB\f(CB$SHELL\fB\fR variable has not been set, then, by default, /bin/sh is executed. Otherwise, if \fIshell command\fR is supplied then it is executed. The exit status of the command executed is stored in the special \fB$?\fR read-only environment variable. .IP "\elock" 4 .IX Item "lock" Locks the current session until the correct password is typed. By default \&\fB\elock\fR attempts to use the \s-1UNIX\s0 password (from /etc/passwd or /etc/shadow) associated with the user running \fIsqsh\fR (if sqsh is linked with the crypt library), however if the \fB\f(CB$lock\fB\fR variable is set then the contents of that is used for validation instead. .SS "Aliases" .IX Subsection "Aliases" The following aliases are established upon startup of \fIsqsh\fR, and are provided primarily for backward compatibility with \fIisql\fR. These may be removed at any time using the \fB\eunalias\fR command (either at the prompt, or within your .sqshrc file). .IP "!" 4 The \fB!\fR alias is provided as a \fB\f(BIcsh\fB\|(1)\fR\-like history mechanism, and is an alias of \fB\ebuf\-append\fR. With release 0.7, this alias is provided only for backwards compatibility with previous releases of \fIsqsh\fR. See \fB\s-1SPECIAL\s0 \&\s-1VARIABLES\s0\fR, \fB\f(CB$history_shorthand\fB\fR for details on the new shorthand mechanism (the new shorthand more closely resembles that of \fBcsh\fR). .IP "clear" 4 .IX Item "clear" An alias for the \fB\eclear\fR command, which causes the contents of the current work buffer to be cleared and discarded. Also the screen will be cleared if readline is compiled into \fIsqsh\fR. .IP "reset" 4 .IX Item "reset" An alias for the \fB\ereset\fR command, which causes the contents of the current work buffer to be cleared and copied to history (if in interactive mode). .IP "exit [x]" 4 .IX Item "exit [x]" .PD 0 .IP "quit [x]" 4 .IX Item "quit [x]" .PD An alias for the \fB\eexit [x]\fR command, causes the current read-eval-print loop to complete. .IP "edit" 4 .IX Item "edit" .PD 0 .IP "vi" 4 .IX Item "vi" .IP "emacs" 4 .IX Item "emacs" .PD These are provided as aliases for the \fB\ebuf\-edit\fR command. See \&\fBCOMMANDS-Buffers\fR for information on the interactions between \fB\ebuf\-edit\fR and aliases. .IP "go" 4 .IX Item "go" Provided as an alias for the \fB\ego\fR command (for obvious reasons). .IP "help" 4 .IX Item "help" An alias for the \fB\ehelp\fR command. .PP \fIIn-Line \ego\fR .IX Subsection "In-Line go" .PP If the variable \fB\f(CB$semicolon_hack\fB\fR is set to 1 (on), then sqsh supports what is called an in-line \fB\ego\fR feature. This allows the current command batch to be terminated and sent to the database in a single step by appending a ';' onto the end of the current work buffer. This allows .PP .Vb 1 \& 1> sp_who; .Ve .PP To behave in the same manner as if you had typed: .PP .Vb 2 \& 1> sp_who \& 2> \ego .Ve .PP Likewise, anything following the semicolon is passed to the \fB\ego\fR command just as if it was run as a normal command: .PP .Vb 1 \& 1> sp_who ; 2>/dev/null | more .Ve .PP Unlike most other \fIisql\fR replacements, \fIsqsh\fR attempts to be smart about the semicolons. If a semicolon is contained within a set of single or double quotes it will not be interpreted. This includes multiple quotes. For example: .PP .Vb 2 \& 1> select "This is a multiple line \& 2> quote; it is smart!" ; .Ve .PP In the above example, only the second semicolon (the one at the end of the line) will be interpreted. The variable \fB\f(CB$semicolon_cmd\fB\fR is a string that contains the command that will be substituted by the semicolon which is \fB\ego\fR by default. But you can change that to \fB\ebcp\fR for example and execute: .PP .Vb 1 \& 1> select * from pubs2..titles; \-S... tempdb..titles .Ve .PP In sqsh\-2.2.0 you can also set variable \fB\f(CB$semicolon_hack2\fB\fR to allow multiple commands on one line to be fired by a semicolon. If this option is set you cannot use the construct above to pass additional parameters to the \fB\ego\fR command. But of course you can change \fB\f(CB$semicolon_cmd\fB\fR to your needs as this command will be used to execute \s-1SQL\s0 batches. .PP .Vb 1 \& echo "exec sp_who;exec sp_helpdb;\eecho Done;" | sqsh \-S... \-U... \-P... .Ve .PP In this example the semicolon acts as a \fB\ego\fR command to a \s-1SQL\s0 buffer and as a command separator for sqsh commands that will be executed in sequence. Note that \fB\f(CB$semicolon_hack2\fB\fR takes precedence over \fB\f(CB$semicolon_hack\fB\fR. .SH "SPECIAL VARIABLES" .IX Header "SPECIAL VARIABLES" There are several options that are configurable via the command line options to \&\fIsqsh\fR, however these are by no means complete. There are many aspects of \&\fIsqsh\fR's behavior that may only be modified by setting special variables. (In fact, the command line options really only set these variables for you). .SS "Variable Data types" .IX Subsection "Variable Data types" Next to all of the variables that follow is the type of data with which they may be set. Any attempts to set the variable with a type of data that it does not accept will fail. .IP "string" 4 .IX Item "string" Any sequence characters. .IP "boolean" 4 .IX Item "boolean" A positive \fIboolean\fR value may be represented as either \*(L"True\*(R", \*(L"Yes\*(R", \*(L"1\*(R", or \&\*(L"On\*(R" (case insensitive) and a negative boolean value may be represented as \&\*(L"False\*(R", \*(L"No\*(R", \*(L"0\*(R", or \*(L"Off\*(R" (case insensitive). However, internally the value of the variable will always be represented as either a \*(L"1\*(R" or \*(L"0\*(R". .IP "path" 4 .IX Item "path" Must be the \fIpath\fR name that is readable by the \fIsqsh\fR program. .IP "int" 4 .IX Item "int" Must be one or more digits. Note that some variables also restrict the range of the integer. .IP "date-spec" 4 .IX Item "date-spec" This is a string of the format used to specify dates and times for the \&\fB\f(BIdate\fB\|(1)\fR command, or the \fBstrftime(3C)\fR and \fBcftime(3C)\fR standard C library functions. For example '%H:%M:%S' specifies a time of hours in 24 hour format, followed by a colon, followed by minutes, followed by a colon, followed by seconds. .IP "float-format" 4 .IX Item "float-format" A string of the format \fBp.s\fR, where \fBp\fR is the total precision of a floating point value (the total number of digits to be displayed, including those following the decimal) and \fBs\fR is the scale of the value (the total number of digits following the decimal to be displayed). .PP \fIVariables\fR .IX Subsection "Variables" .PP The following variables have special meanings within \fIsqsh\fR and the setting of these variables alter the behavior of the shell. .IP "$? (int)" 4 .IX Item "$? (int)" This read-only variable may contain the following return value: .RS 4 .IP "\(bu" 4 The most recent error number returned from the \s-1SQL\s0 Server (@@errno) of severity > 10 (above informational messages). .IP "\(bu" 4 The exit value of a previously executed pipe command. .IP "\(bu" 4 The return value of the most recently executed sqsh function. .IP "\(bu" 4 The result of the last executed \eif statement: .RS 4 .IP "0 \- The test evaluated to True." 4 .IX Item "0 - The test evaluated to True." .PD 0 .IP "1 \- The test evaluated to False." 4 .IX Item "1 - The test evaluated to False." .IP "2 \- There was an error in the test specification." 4 .IX Item "2 - There was an error in the test specification." .RE .RS 4 .RE .RE .RS 4 .RE .IP "$# (int)" 4 .IX Item "$# (int)" .PD Contains the number of arguments passed into the sqsh function or script. .IP "$* (string list)" 4 .IX Item "$* (string list)" Expands to the complete list of arguments supplied to the function or script when invoked. .IP "${0}...${N} (int)" 4 .IX Item "${0}...${N} (int)" Used to reference positional function arguments. Argument ${0} is the name of the function being called, ${1} is the first argument, etc. .IP "$$" 4 Expands to the process \s-1ID\s0 of the current running sqsh session. .IP "\s-1DISPLAY\s0" 4 .IX Item "DISPLAY" May contain the name of the \s-1DISPLAY\s0 the X\-server uses to put the XWindows result window when using \fB\ego \-x\fR. Defaults to the \fI\f(CI$DISPLAY\fI\fR shell environment. .IP "appname" 4 .IX Item "appname" Contains the name \fIsqsh\fR uses to identity itself to the server. Defaults to sqsh\-2.1.7. The application name can be retrieved from the sysprocesses table like: select program_name from master.dbo.sysprocesses where spid=@@pid; .IP "autouse (string)" 4 .IX Item "autouse (string)" Note: the meaning of this variable has been deprecated. .Sp If \fB\f(CB$autouse\fB\fR is set, and the \fB\f(CB$database\fB\fR variable has not been set, then this variable causes \fB\econnect\fR to perform a "use \fB\f(CB$autouse\fB\fR" once a connection has been established. .Sp This variable may also be set using the \fB\-D\fR command line option. .IP "banner (boolean)" 4 .IX Item "banner (boolean)" Turns off the banner message displayed on startup, this variable defaults to 1 and may also be turned off using the \fB\-b\fR command line argument. .IP "batch_failcount (int)" 4 .IX Item "batch_failcount (int)" This internal variable is used to keep track of the number of batches that have failed to execute (essentially, the number of times that the error handler was called). .Sp A batch is considered failed whenever an error of severity \fB\f(CB$thresh_fail\fB\fR is encountered. When \fB\f(CB$batch_failcount\fB\fR reaches \fB\f(CB$thresh_exit\fB\fR \fIsqsh\fR exits with an exit value of the total number of batches that have failed. Setting \&\fB\f(CB$batch_failcount\fB\fR to the string "" will cause it to reset to zero, any other value may have unpredictable results. .Sp See \fB\s-1EXIT\s0 \s-1STATUS\s0\fR for details. .IP "batch_pause (boolean)" 4 .IX Item "batch_pause (boolean)" Causes a \*(L"Paused. Hit enter to continue...\*(R" message to be displayed after each batch is executed. This variable, in conjunction with \fB\f(CB$echo\fB\fR is good for debugging \s-1SQL\s0 scripts specified with the \fB\-i\fR option. .IP "bcp_colsep (string)" 4 .IX Item "bcp_colsep (string)" Used as a separator between columns during \s-1BCP\s0 style output (see the \fB\f(CB$style\fB\fR configuration variable and the \fB\-m\fR option to the \fB\ego\fR command). The default setting is \*(L"|\*(R". .IP "bcp_rowsep (string)" 4 .IX Item "bcp_rowsep (string)" Used as a separator between rows during \s-1BCP\s0 style output (see the \fB\f(CB$style\fB\fR configuration variable and the \fB\-m\fR option to the \fB\ego\fR command). Note that, a newline (\*(L"\en\*(R") is automatically appended and should not be supplied. The default setting is \*(L"|\*(R". .IP "bcp_trim (boolean)" 4 .IX Item "bcp_trim (boolean)" Controls whether or not \s-1BCP\s0 style output trims trailing spaces from fixed length columns. The default is \*(L"True\*(R". .IP "builddate (none)" 4 .IX Item "builddate (none)" Read only variable specifying the date when the \fIsqsh\fR executable was compiled. .IP "buildtime (none)" 4 .IX Item "buildtime (none)" Read only variable specifying the time when the \fIsqsh\fR executable was compiled. .IP "chained (boolean)" 4 .IX Item "chained (boolean)" If set then sqsh uses the \*(L"chained\*(R" transaction mode (aka \*(L"AutoCommit off\*(R"). Setting this has \s-1NO\s0 effect on the current connection. It can be set via the command line argument \fB\-n\fR. .IP "charset (string)" 4 .IX Item "charset (string)" If this variable is set prior to establishing a connection with \s-1SQL\s0 Server, then during the connection \fIsqsh\fR will request that the server transform to and from the requested \fIcharset\fR. After establishing a connection, this variable is automatically set to the current character set in use. .IP "clear_on_fail (boolean)" 4 .IX Item "clear_on_fail (boolean)" Normally, whenever the \fB\ego\fR command is run, \fIsqsh\fR clears the current work buffer of its contents, moving them to history. Setting \fB\f(CB$clear_on_fail\fB\fR to 0, leaves the current work buffer intact if a failure is encountered while sending the contents to the database. The default value is 1, or on. .IP "colsep (string)" 4 .IX Item "colsep (string)" Causes the string \fIcolsep\fR to be used to delimit \s-1SQL\s0 column output columns, this defaults to \*(L" \*(R", it may also be set via the command line argument \fB\-s\fR. .IP "colwidth (int)" 4 .IX Item "colwidth (int)" Used to control the maximum column width displayed by the \fBpretty\fR display style (see \fB\f(CB$style\fB\fR below). If a row of a column exceeds this width, it will be wrapped in a relatively visually appealing manner at \fB\f(CB$colwidth\fB\fR characters. Note, however, that if there is enough screen width to hold all columns \&\fB\f(CB$colwidth\fB\fR may be exceeded until the width of the screen is reached. .IP "database (string)" 4 .IX Item "database (string)" If this variable is set prior to establishing a connection to the \s-1SQL\s0 Server, the a "use \fB\f(CB$database\fB\fR" is performed immediately after the connection is established. Once a connection has been established this variable will automatically be set to the current database context. .IP "date (date-spec)" 4 .IX Item "date (date-spec)" This variable may be set with a date format (see the man page for \fB\f(BIdate\fB\|(1)\fR), and the variable expands to the current date in the supplied format. The default format for this variable is \f(CW%d\fR\-%b\-%y (e.g. 02\-Feb\-1996). .IP "datefmt (date-spec)" 4 .IX Item "datefmt (date-spec)" This variable may be set with a date format similar to \fB\f(CB$date\fB\fR and is used to control the display format of all \s-1SQL\s0 Server \s-1DATE\s0 columns. (Similar to \fB\f(CB$datetime\fB\fR.) Note that only 63 bytes are available in total for the expanded string and the remainder will be truncated. .IP "datetime (date-spec)" 4 .IX Item "datetime (date-spec)" This variable may be set with a date format similar to \fB\f(CB$date\fB\fR and \fB\f(CB$time\fB\fR and is used to control the display format of all \s-1SQL\s0 Server \s-1DATETIME\s0, \s-1BIGDATETIME\s0 and \s-1SMALLDATETIME\s0 columns. Note that only 63 bytes are available in total for the expanded string and the remainder will be truncated. .Sp Note that this features relies upon the operating system specific locale information and the setting of \fB\f(CB$localeconv\fB\fR for determining such things as the name of the month and day, rather than going through the CT-Lib locale information. This means that the date format could potentially miss-match the locale as requested using the \fB\-z\fR flag. For example, if \fIsqsh\fR is run on an operating system configured for \s-1US\s0 English, but requests French as the language of choice using \fB\-z\fR, the use of \fB\f(CB$datetime\fB\fR will cause all date information to be displayed in \s-1US\s0 English rather than French. .Sp Ordinary characters defined in the variable are left in place without any conversion. Characters introduced by a '%' character are replaced during display of a column value according to the definitions in the \fBstrftime\fR manual page. .RS 4 .IP "[]" 4 Any contained between a pair of braces ('[' and ']') will be removed when displaying \s-1SMALLDATETIME\s0 columns. This feature is particularly useful for removing the seconds, milliseconds or microseconds values which are not applicable to \s-1SMALLDATETIME\s0 anyway. For \s-1DATETIME\s0 or \s-1BIGDATETIME\s0 columns, only the actual braces will be removed. .ie n .IP "%q" 4 .el .IP "\f(CW%q\fR" 4 .IX Item "%q" Specifies the milliseconds for \s-1DATETIME\s0 and \s-1TIME\s0 and microseconds for \&\s-1BIGDATETIME\s0 and \s-1BIGTIME\s0 data types. In previous versions of sqsh the \fI\f(CI%u\fI\fR specifier was used for the millisecond part of the datetime datatype. However, as \fI\f(CI%u\fI\fR is used by \fBstrftime\fR to denote the day number of the week, this is replaced by \fI\f(CI%q\fI\fR since sqsh\-2.3. For example when using the default C locale: .Sp .Vb 4 \& 1> \eset datetime=\*(Aq%e %b %Y %H:%M[:%S.%q]%p\*(Aq \& 1> select convert(bigdatetime,getdate()) \& 2> select convert(smalldatetime,getdate()) \& 3> go \& \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \& 22 Jul 2013 13:26:52.938000PM \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \& 22 Jul 2013 13:27PM .Ve .RE .RS 4 .RE .IP "debug (string)" 4 .IX Item "debug (string)" If \fIsqsh\fR has been compiled with debugging enabled (\-DDEBUG), this variable may be used to control the amount of debugging output displayed. \fB\f(CB$debug\fB\fR may be set to a pipe (|) delimited (logical \s-1OR\s0) set of the following words to turn on various pieces of debugging: \fB\s-1ALIAS\s0\fR, \fB\s-1AVL\s0\fR, \fB\s-1BCP\s0\fR, \fB\s-1DISPLAY\s0\fR, \fB\s-1ENV\s0\fR, \&\fB\s-1ERROR\s0\fR, \fB\s-1EXPAND\s0\fR, \fB\s-1FD\s0\fR, \fB\s-1HISTORY\s0\fR (abbr. \fB\s-1HIST\s0\fR), \fB\s-1JOB\s0\fR, \&\fB\s-1READLINE\s0\fR (abbr. \fB\s-1RL\s0\fR), \fB\s-1RPC\s0\fR, \fB\s-1SCREEN\s0\fR, \fB\s-1SIG\s0\fR, \fB\s-1SIGCHLD\s0\fR (or \fB\s-1SIGCLD\s0\fR), \&\fB\s-1TDS\s0\fR or \fB\s-1ALL\s0\fR. Can also be set through the \fI\-l\fR startup option. .IP "debug_tds_capture (string)" 4 .IX Item "debug_tds_capture (string)" When \fB\s-1TDS\s0\fR debugging is enabled and this variable is defined with a valid file name, a debugging trace will be logged into this file that can be analyzed with Ribo. You might need the devlib versions of the OpenClient library to link with sqsh to be able to use this option. See for more information the ct_debug function in the Sybase \s-1SDK\s0 documentation. .IP "debug_tds_logdata (string)" 4 .IX Item "debug_tds_logdata (string)" When \fB\s-1TDS\s0\fR debugging is enabled and this variable is defined with a valid filename, a debugging log will be written by OpenClient with all possible debugging info (\s-1CS_DBG_ALL\s0). See also option above. .IP "defer_bg (boolean)" 4 .IX Item "defer_bg (boolean)" Normally, when a job is run in the background (via a '&' on the command line), the output of the job is deferred to a temporary file (located in \&\fI\f(CI$tmp_dir\fI\fR) until the user requests the output to be displayed using \fB\eshow jobid\fR. This way the results of the job will not interfere with what the user is doing. Setting this variable to false will result in no deferred output files being created and output sent to the screen immediately .IP "echo (boolean)" 4 .IX Item "echo (boolean)" Setting \fB\f(CB$echo\fB\fR to on (1) causes each command submitted to the database via the \&\fB\ego\fR command to be displayed prior to the output. This variable defaults to 0 (or off), and may also be set using the \fB\-e\fR command line option. .IP "encryption (boolean)" 4 .IX Item "encryption (boolean)" Setting the \fB\f(CB$encryption\fB\fR variable prior to establishing a connection to the server will cause the login connection to be initiated using client-side password encryption. This variable may also be set using the \fB\-X\fR command line option. Client-side password encryption will also occur when using the \fB\-X\fR option on the \fB\econnect\fR, \fB\ereconnect\fR or \fB\ebcp\fR commands. Please note that the Sybase \s-1ASE\s0 setting for the \fBnet password encryption reqd\fR (15.0.2) configuration parameter may enforce you to use client side password encryption. \fIsqsh\-2.1.9\fR supports \s-1RSA\s0 password encryption when the CT-Lib version in use supports it. \s-1RSA\s0 password encryption is required if the above mentioned \s-1ASE\s0 configuration parameter is set to \fB2\fR. Older version of sqsh only supports a value of \fB1\fR (CT-Lib internal encryption algorithms). .IP "exit_failcount (boolean)" 4 .IX Item "exit_failcount (boolean)" Settings this value to 1 causes \fIsqsh\fR to return an exit status of \&\fB\f(CB$batch_failcount\fB\fR rather than 0, upon a non-error termination. See \fB\s-1EXIT\s0 \&\s-1STATUS\s0\fR for details. The default value is 0. .IP "exit_value (int)" 4 .IX Item "exit_value (int)" When you exit sqsh by specifying an exit code, like \fB\eexit 3\fR or using one of the aliases \fBexit\fR or \fBquit\fR commands, then this value is assigned to the \&\fB\f(CB$exit_value\fB\fR variable. You can also assign a value using the \fB\eset\fR command. When sqsh determines this variable has a non-zero value during termination, this value will be used as exit code. See \fB\s-1EXIT\s0 \s-1STATUS\s0\fR for details. .IP "expand (boolean)" 4 .IX Item "expand (boolean)" By default when the \fB\ego\fR command is executed, the contents of the current work buffer is expanded of all environment variables prior to being sent to the database for execution. By setting this variable to \*(L"0\*(R", the buffer will no longer be expanded before being sent to the database. This is useful when you either (1) have strings in the buffer that contain a '$' and you don't want them to be expanded, or (2) for performance reasons; it takes time (and an extra copy of the buffer) to perform the variable expansion. .IP "filter (boolean)" 4 .IX Item "filter (boolean)" Toggles filtering of the \s-1SQL\s0 batch through an external program (defined by the \&\fB\f(CB$filter_prog\fB\fR variable, below) prior to being sent to the \s-1SQL\s0 Server. Default is '0', or 'off'. .IP "filter_prog (string)" 4 .IX Item "filter_prog (string)" Defines the external program through which the \s-1SQL\s0 batch will be filtered prior to being sent to the \s-1SQL\s0 Server. This variable is ignored if \fB\f(CB$filter\fB\fR is set to '0' or 'off'. The default is 'm4 \-'. .IP "float (float-format)" 4 .IX Item "float (float-format)" Defines the display format (the precision and scale) for all floating point values displayed by sqsh. The default is '18.6'. Note that values exceeding the defined precision are not truncated, so setting this value too low may cause columns in a result set to be miss-aligned. .IP "footers (boolean)" 4 .IX Item "footers (boolean)" Toggles the \*(L"(%d rows affected)\*(R" following a result set. The default for this variable is '1'. .IP "headers (boolean)" 4 .IX Item "headers (boolean)" Toggles the column headers preceding a result set. The default for this variable is '1'. .IP "help_dir (path)" 4 .IX Item "help_dir (path)" This is the location of the help files used by the \fB\ehelp\fR command, typically it defaults to something like /usr/local/lib/sqsh/help. .IP "hist_auto_save (int)" 4 .IX Item "hist_auto_save (int)" When variable \fB\f(CB$histsave\fB\fR is on and the \fB\f(CB$hist_auto_save\fB\fR variable has a value greater than 0, then the history will be automatically saved to \fB\f(CB$history\fB\fR after \fB\f(CB$hist_auto_save\fB\fR modifications of the history buffers. When the value is 0 (default), then no automatic history save will be performed. .IP "histmerge (boolean)" 4 .IX Item "histmerge (boolean)" When this option is on, sqsh will merge the contents of the history on disk with the history in memory before writing the history back to disk. This is to prevent data loss in the history file when other sqsh sessions have also written to the same history file on disk. This option is off by default which will just overwrite the existing history file when you exit sqsh or the history is being automatically saved because of \fB\f(CB$hist_auto_save\fB\fR being set. .IP "histnum (int)" 4 .IX Item "histnum (int)" Contains the history number that will be assigned to the current command batch as soon as the \fB\ego\fR command is executed. This variable should be considered read-only. See also the discussion on the \fB\f(CB$histunique\fB\fR variable. .IP "history (path)" 4 .IX Item "history (path)" This is the location of the history file used to store and retrieve a user's history during start-up and shutdown. This defaults to \fI\f(CI$HOME\fI/.sqsh_history\fR. This variable is expanded each time it is referenced by sqsh, much in the same way that \fB\f(CB$prompt\fB\fR is referenced each time the prompt is displayed. .IP "history_shorthand (boolean)" 4 .IX Item "history_shorthand (boolean)" This variable is only meaningful within an interactive session. If set, it turns on the ability to append any named buffer or history buffer onto the current work buffer in a 'sh' history style, such as '!40'. Be careful with this feature, \fIsqsh\fR is not terribly intelligent with looking for history shorthand, so it is possible that it may get confused (although, it is smart enough to ignore !'s in quoted strings). .IP "histsave (boolean)" 4 .IX Item "histsave (boolean)" The value of this variable is used by \fIsqsh\fR to indicate whether the history should be saved to \fB\f(CB$history\fB\fR prior to termination of sqsh. .IP "histsize (int)" 4 .IX Item "histsize (int)" The value of this variable is used to alter the maximum number of history entries are maintained by \fIsqsh\fR (the default is 10). Note that decreasing the value of this variable causes some history entries to be lost. .IP "histunique (boolean)" 4 .IX Item "histunique (boolean)" If set, \fIsqsh\fR maintains a MRU-LRU order of executed buffers and does not store duplicate command buffers. For example, observe the following situation: .Sp .Vb 10 \& LINUX1502.user1.master.1> \ehistory \& (1) sp_who \& (2) grant role mon_role to sa_role \& (3) select * from monProcessActivity \& (4) select @@authmech,show_sec_services() \& (5) select @@servername,@@authmech,show_sec_services() \& LINUX1502.user1.master.1> sp_who \& LINUX1502.user1.master.2> go \& ... output omitted \& LINUX1502.user1.master.1> \ehistory \& (1) grant role mon_role to sa_role \& (2) select * from monProcessActivity \& (3) select @@authmech,show_sec_services() \& (4) select @@servername,@@authmech,show_sec_services() \& (5) sp_who .Ve .Sp \&\fIsp_who\fR is the last executed command and the buffer \- originally the last in the list \- is now on top of the list. When an already existing buffer is reused, the value of the \fB\f(CB$histnum\fB\fR variable is not changed. .IP "hostname (string)" 4 .IX Item "hostname (string)" Used during the connection process to indicate to \s-1SQL\s0 Server the name of the host from which \fIsqsh\fR is connecting. This variable may also be set using the \&\fB\-H\fR flag. .IP "ifs (string)" 4 .IX Item "ifs (string)" The list of Internal Field Separators. .IP "ignoreeof (boolean)" 4 .IX Item "ignoreeof (boolean)" By default, \fIsqsh\fR terminates if the user presses ^d (control-D) on an empty line and readline support is compiled in. If \fB\f(CB$ignoreeof\fB\fR is set in the sqshrc file you get a warning message instead: .Sp .Vb 1 \& CTRL\-D: Use "exit" or "quit" to leave the sqsh shell. .Ve .Sp This is equivalent to using \*(L"set \-o ignoreeof\*(R" in the bash shell. .IP "interactive (boolean)" 4 .IX Item "interactive (boolean)" This is a variable used internally and should probably not be altered by the user. If \fB\f(CB$interactive\fB\fR is '0', then the prompt is not displayed, the history is neither read nor written and some user messages are suppressed. .IP "interfaces (path)" 4 .IX Item "interfaces (path)" This is the full path name of the interfaces file, it defaults to \&\fI\f(CI$SYBASE\fI/interfaces\fR. .IP "keytab_file (string)" 4 .IX Item "keytab_file (string)" Used in Kerberos and \s-1DCE\s0 user authentication security mechanisms. Corresponds with the \fB\-K\fR startup option. .Sp See also the discussion on Kerberos Support. .IP "keyword_completion (int/string)" 4 .IX Item "keyword_completion (int/string)" This variable only applies if \s-1GNU\s0 Readline support has been compiled into \&\fIsqsh\fR. \fB\f(CB$keyword_completion\fB\fR is used to control the T\-SQL keyword completion feature in readline, and may be set using either an integer between 0 and 4, or one of the strings \fInone\fR, \fIlower\fR, \fIupper\fR, \fIsmart\fR, or \fIexact\fR. If it is set to either 0 or \fInone\fR, then no keyword completion is performed (this is the default). \fIlower\fR or 1, causes \fIsqsh\fR to complete the keyword in lowercase, regardless of the case that the partially completed keyword was typed. \fIupper\fR or 2 forces completion to be performed in upper case, \fIsmart\fR, or 3, bases the decision on case upon the first character of the partial keyword, and \fIexact\fR completes the keyword in exactly the same case as defined in the \fI.sqsh_words\fR (for the built-in T\-SQL keywords, this will be lower case). New in \fIsqsh\-2.5\fR is that when regular Readline completion does not match the typed string with a keyword, then filename completion will be tried in the current directory. For example: .Sp .Vb 3 \& SYBASE.sa.master.1> \elcd $SYBASE/$SYBASE_ASE/scripts \& \elcd: local directory changed to: /opt/sybase/ASE\-15_0/scripts \& SYBASE.sa.master.1> \erun \-n \-i ./instm .Ve .Sp results in the completed filename \*(L"./instmsgs.ebf\*(R". .IP "keyword_dynamic (boolean)" 4 .IX Item "keyword_dynamic (boolean)" This variable controls the dynamic loading of keywords in the completion list when initially logging in to the server or when the database context is changed using the \fIuse database\fR command. When this variable is set to 'On' (default is 'Off'), then the query that is provided through the \&\fB\f(CB$keyword_query\fB\fR variable is executed and the query result set is loaded into the Readline completion list. This will only work for Sybase \s-1ASE\s0 and Microsoft \&\s-1SQL\s0 servers. This variable also controls dynamic loading of a column list to be auto\- completed by Readline. When an object name is followed by a dot and \s-1TAB\s0 completion is requested, \fIsqsh\fR dynamically creates a list of columns that belongs to the object (table, view, procedure) and allows for Readline \s-1TAB\s0 completion of the column or parameter names. This feature is only available if \&\s-1GNU\s0 Readline support has been compiled into \fIsqsh\fR and \fB\f(CB$keyword_completion\fB\fR is set to a value greater than zero. In sqsh\-2.4 it is also possible to use the object alias in the \s-1SQL\s0 buffer for auto-completion. For example when you enter the following query in the buffer and type the \s-1TAB\s0 key twice after the alias 'd' and the dot, a list of column names will be produced for the \&'sysdatabases' table for further completion: .Sp .Vb 9 \& SYBPROD.sa.tempdb.1> select * from master..sysdatabases d, \& SYBPROD.sa.tempdb.2> master.dbo.sysusages u \& SYBPROD.sa.tempdb.3> where d. \& d.audflags d.def_remote_loc d.durability d.status2 \& d.audflags2 d.def_remote_type d.logptr d.status3 \& d.crdate d.deftabaud d.name d.status4 \& d.dbid d.defvwaud d.spare d.suid \& d.defpraud d.dumptrdate d.status d.version \& SYBPROD.sa.tempdb.3> where d. .Ve .Sp This works both for the T\-SQL join syntax and the \s-1ANSI\s0 inner, outer, left and right join syntax. Note that sqsh is now able to perform cross database auto-completion as well. .IP "keyword_file (string)" 4 .IX Item "keyword_file (string)" If Readline support has been compiled into \fIsqsh\fR, and \fIsqsh\fR is being run in interactive mode, the contents of this file are used for keyword tab completion by Readline rather than the default set of T\-SQL syntactical keywords. The default is \fI\f(CI$HOME\fI/.sqsh_words\fR. When \fB\f(CB$keyword_dynamic\fB\fR is enabled this takes precedence and overrules the list loaded from \fB\f(CB$keyword_file\fB\fR. .IP "keyword_query (string)" 4 .IX Item "keyword_query (string)" This variable contains the query that will be executed when a change of database is detected or during initial login (Msg 5701). The default query is: .Sp .Vb 1 \& select name from sysobjects order by name .Ve .Sp But you can supply a different query that suits your needs even better. E.g. .Sp .Vb 7 \& \eset keyword_query="\e\e \& select name from sysobjects \e\e \& where type in (\*(AqU\*(Aq,\*(AqV\*(Aq,\*(AqP\*(Aq,\*(AqS\*(Aq) \e\e \& union \e\e \& select name from sybsystemprocs..sysobjects \e\e \& where type=\*(AqP\*(Aq \e\e \& order by name" .Ve .Sp This feature is controlled by the variables \fB\f(CB$keyword_completion\fB\fR and \&\fB\f(CB$keyword_dynamic\fB\fR and is only available if \s-1GNU\s0 Readline support has been compiled into \fIsqsh\fR. .IP "language (string)" 4 .IX Item "language (string)" The \fB\f(CB$language\fB\fR variable is used while establishing a connection to the server to specify the national language used to display system prompts and messages. The variable will automatically track the current language setting of the server. This may also be set via the \fB\-z\fR flag. .IP "lineno (int)" 4 .IX Item "lineno (int)" This is an internal variable and should not be altered by the user. It is used to maintain the line number that is being typed into within the current work buffer. .IP "linesep (string)" 4 .IX Item "linesep (string)" Used to configure the line separator for the horizontal display style, this defaults to \*(L"\en\et\*(R". .IP "localeconv (boolean)" 4 .IX Item "localeconv (boolean)" A boolean variable that when set to true will result in the Operating System locale to be used for displaying all datetime (\s-1DATETIME\s0, \s-1SMALLDATETIME\s0, \s-1TIME\s0, \&\s-1DATE\s0, \s-1BIGDATETIME\s0 and \s-1BIGTIME\s0) and the numeric, decimal, real, float and money/smallmoney datatypes in the result set. When this variable is set to false (i.e. the default), sqsh will use the internal C/POSIX locale to determine how to display these datatypes. For example: .Sp .Vb 10 \& ~$ export LANG=nl_NL.utf8 \& ~$ locale \-ck LC_TIME \& LC_TIME \& abday="zo;ma;di;wo;do;vr;za" \& day="zondag;maandag;dinsdag;woensdag;donderdag;vrijdag;zaterdag" \& abmon="jan;feb;mrt;apr;mei;jun;jul;aug;sep;okt;nov;dec" \& mon="januari;februari;maart;april;mei;juni;juli;augustus;september;oktober; \& november;december" \& am_pm=";" \& ... \& \& ~$ sqsh \-Llocaleconv=On \-Ldatetime="%A %e %B %Y" \-C"select getdate()" \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \& maandag 22 juli 2013 \& \& (1 row affected) \& ~$ sqsh \-Llocaleconv=Off \-Ldatetime="%A %e %B %Y" \-C"select getdate()" \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \& Monday 22 July 2013 \& \& (1 row affected) .Ve .Sp Also, depending on the locale, the decimal specifier in money, numeric, decimal, float and real datatypes may be displayed as a \fB\*(L",\*(R"\fR. Note that sqsh does not take the thousands_sep into account when displaying numerical data values. .IP "lock (string/write\-only)" 4 .IX Item "lock (string/write-only)" Defines the password to be used by the \fB\elock\fR command. If unset or set to the string \*(L"\s-1NULL\s0\*(R", then the \s-1UNIX\s0 password of the user running \fIsqsh\fR is used instead (if possible). Note that \fB\f(CB$lock\fB\fR will always expand to the string \&\*(L"*lock*\*(R" if referenced. .IP "login_timeout (int)" 4 .IX Item "login_timeout (int)" The number of seconds to wait when attempting to create a new connection to a data server. Default is 0 (infinite wait). See also the \fB\-T\fR command line option. .IP "max_timeout (int)" 4 .IX Item "max_timeout (int)" Controls the number of times a query needs to reach its time-out value before the session is aborted. See \fB\f(CB$query_timeout\fB\fR and the \fB\-Q\fR command line flag. The following messages will be displayed and sqsh exits with value 255 when the \&\fB\f(CB$max_timeout\fB\fR limit is reached. .Sp .Vb 3 \& Query or command timeout detected, session aborted \& The client connection has detected this x time(s) \& Aborting on max_timeout limit .Ve .IP "maxlen (int)" 4 .IX Item "maxlen (int)" Controls the maximum amount of data that will be displayed (in any display mode) in a single column. This setting will automatically truncate the output of particularly large data types (such as \s-1TEXT\s0) to the value supplied. The default setting is 32768 bytes (32KB). .IP "newline_go (boolean)" 4 .IX Item "newline_go (boolean)" This flag is used as a horrible kludge to support an \*(L"empty\*(R" alias for the \&\fB\ego\fR command, that is, the equivalent of supplying \*(L"\-c ''\*(R" or just \*(L"\-c\*(R" on the command line. When on, an empty line is interpreted as a call to the \fB\ego\fR command. This feature is not recommended but is supplied for completeness. .IP "nosepline (boolean)" 4 .IX Item "nosepline (boolean)" Suppress the separator lines with the pretty output style. .IP "output_parms (boolean)" 4 .IX Item "output_parms (boolean)" Flag used to enable or disable the display of output parameter result sets from stored procedures. The default is to enable the display. .IP "p2faxm (int)" 4 .IX Item "p2faxm (int)" Implements the feature Print messages to File (P2F). This variable is used in conjuction with \fB\f(CB$p2fname\fB\fR and specifies a threshold on the number of messages per batch that will be send to the terminal window. If the threshold is exceeded, the remaining messages will be send to the specified file. The default value is \s-1NULL\s0 which disables the P2F feature. Also an assigned value of 0 disables this feature. This feature will only work in interactive mode and is to prevent an accidental flood of server messages scrolling over the screen. For example: .Sp .Vb 10 \& SYBASE.sa.tempdb.1> \eset p2fname=/tmp/sqsh_p2f.out \& SYBASE.sa.tempdb.1> \eset p2faxm=10 \& SYBASE.sa.tempdb.1> create clustered index keys_cx on keys(id) \& SYBASE.sa.tempdb.2> with ignore_dup_row \& SYBASE.sa.tempdb.2> go \& Warning: deleted duplicate row. Primary key is \*(Aq0\*(Aq \& Warning: deleted duplicate row. Primary key is \*(Aq1\*(Aq \& Warning: deleted duplicate row. Primary key is \*(Aq2\*(Aq \& Warning: deleted duplicate row. Primary key is \*(Aq3\*(Aq \& Warning: deleted duplicate row. Primary key is \*(Aq4\*(Aq \& Warning: deleted duplicate row. Primary key is \*(Aq5\*(Aq \& Warning: deleted duplicate row. Primary key is \*(Aq6\*(Aq \& Warning: deleted duplicate row. Primary key is \*(Aq7\*(Aq \& Warning: deleted duplicate row. Primary key is \*(Aq8\*(Aq \& Warning: deleted duplicate row. Primary key is \*(Aq9\*(Aq \& Warning: Number of printed server messages exceeds p2faxm=10 limit for current batch. \& Remaining server messages will be printed to file: /tmp/sqsh_p2f.out .Ve .IP "p2fname (path)" 4 .IX Item "p2fname (path)" Contains the filename for the Print messages to File (P2F) feature described above. Default is \s-1NULL\s0 which disables the P2F feature. If a file is specified that already exists, then new data will be appended. .IP "packet_size (int)" 4 .IX Item "packet_size (int)" Defines the size of the \s-1TDS\s0 packets used to communicate with \s-1SQL\s0. Changing the value of the variable will not affect the current connection but will take effect upon the next \fB\ereconnect\fR command. Specifying a value of \s-1NULL\s0 indicates that the default packet size is desired. .IP "password (string/write\-only)" 4 .IX Item "password (string/write-only)" This is the user's current password. A \s-1NULL\s0 password may be assigned using an explicit \*(L"\s-1NULL\s0\*(R" string. For security reasons, when referenced the \fB\f(CB$password\fB\fR variable will always expand to the string \*(L"*password*\*(R". .IP "password_retry (boolean)" 4 .IX Item "password_retry (boolean)" When the variable is on and sqsh started in interactive mode, sqsh will ask for the password again if login failed. When set to 'off', sqsh will terminate immediately. Default is on. .IP "principal (string)" 4 .IX Item "principal (string)" Used in Kerberos user authentication as the Server principal name when it differs from the \fB\f(CB$DSQUERY\fB\fR name. Corresponds with the \fB\-R\fR startup option. .Sp See also the discussion on Kerberos Support. .IP "prompt (string)" 4 .IX Item "prompt (string)" This variable is used by \fIsqsh\fR to build your current prompt. Any variables contained within \fB\f(CB$prompt\fB\fR are expanded each time the prompt is displayed. The default value for this is '${lineno}> '. See also the discussion on color support below. .IP "prompt2 (string)" 4 .IX Item "prompt2 (string)" This contents of this prompt are expanded and displayed during interactive use when \fIsqsh\fR requires additional input, such as during a line continuation. The default value is '\-\-> '. .IP "query_timeout (int)" 4 .IX Item "query_timeout (int)" Number of seconds to wait for a query to return data. If the timeout is reached the query is aborted (canceled). See also \fB\f(CB$max_timeout\fB\fR and the \fB\-Q\fR command line option. .IP "rcfile (path)" 4 .IX Item "rcfile (path)" Contains a colon (:) delimited list of sqsh resource (sqshrc) files. The default setting is /etc/sqshrc followed by \fI\f(CI$HOME\fI/.sqshrc\fR). .IP "readline_histignore (string)" 4 .IX Item "readline_histignore (string)" If readline support has been compiled into \fIsqsh\fR, you can control which commands or statements on the command line will be filtered from the readline history file specified by \fB\f(CB$readline_history\fB\fR. It is a colon (:) separated string or a string containing a regular expression that is identified by \*(L"\s-1RE:\s0\*(R". For example: .Sp .Vb 3 \& \eset readline_histignore=\*(Aqgo:lo:mo:exit:quit:vi:!!:GO\*(Aq \& or \& \eset readline_histignore=\*(Aq"RE:^[glm]o$|^cd |^exit$|^quit$|^vi$"\*(Aq .Ve .Sp The regular expression in the second example starts with \fI\s-1RE:\s0\fR and it is recommended to supply the string between quotes and double quotes to prevent expansion and display problems due to the pipe characters. The regular expression is evaluated case insensitive. .IP "readline_history (string)" 4 .IX Item "readline_history (string)" If readline support has been compiled into \fIsqsh\fR, the contents of the readline line-by-line history will be written to the file specified by the \&\fB\f(CB$readline_history\fB\fR variable. The default is \fI\f(CI$HOME\fI/.sqsh_readline\fR. .IP "readline_histsize (int)" 4 .IX Item "readline_histsize (int)" If readline support has been compiled into \fIsqsh\fR, the value of \&\fB\f(CB$readline_histsize\fB\fR specifies the number of lines that are saved in the readline line-by-line history. Setting this to a value of 0 causes every line to be saved. The default value is 100. .IP "real (float-format)" 4 .IX Item "real (float-format)" Defines the display format (the precision and scale) for all real values displayed by sqsh. The default is '18.6'. Note that values exceeding the defined precision are not truncated, so setting this value too low may cause columns in a result set to be miss-aligned. .IP "repeat_batch (boolean)" 4 .IX Item "repeat_batch (boolean)" When set to \fBOn\fR or \fBTrue\fR, a \fB\ego\fR executed with an empty \fB\s-1SQL\s0 Buffer\fR will cause the previous batch to be re-executed. .IP "secmech (string)" 4 .IX Item "secmech (string)" The name of the security mechanism used for user authentication. For instance csfkrb5. When using the \fB\-Z\fR option, the name of the security mechanism can be specified, or when no secmech is supplied, the OpenClient will use the default, i.e. the first security entry from the \fI\f(CI$SYBASE\fI/$SYBASE_OCS/config/libtcl.cfg\fR file. Note that the name used must match the name of the corresponding secmech entry in the \fIobjectid.dat\fR file. When the connection to the server is setup, the actual secmech name will be stored in the \fB\f(CB$secmech\fB\fR variable. .IP "secure_options (string)" 4 .IX Item "secure_options (string)" Describe the security options used for user authentication security mechanisms. Corresponds to the \fB\-V\fR startup option. .Sp See also the paragraph on Kerberos Support. .IP "script (string)" 4 .IX Item "script (string)" If \fIsqsh\fR is run using the \fB\-i\fR flag, then this variable contains the name of the script being executed. .IP "semicolon_cmd (string)" 4 .IX Item "semicolon_cmd (string)" When \fB\f(CB$semicolon_hack\fB\fR (see below) is enabled, the contents of this variable is executed when a semicolon is encountered in the \fB\s-1SQL\s0 Buffer\fR. This variable defaults to the string '\fB\ego\fR'. .IP "semicolon_hack (boolean)" 4 .IX Item "semicolon_hack (boolean)" Toggles on the ability to use a ';' as an in-line command terminator. This feature is not recommended and is only in here because enough users complained. See section \fB\s-1COMMANDS\s0, In-Line \ego\fR. .IP "semicolon_hack2 (boolean)" 4 .IX Item "semicolon_hack2 (boolean)" Toggles on the ability to use multiple ';' as an in-line command terminator. See section \fB\s-1COMMANDS\s0, In-Line \ego\fR. .IP "session (string)" 4 .IX Item "session (string)" The location of the session file that will be processed just before connecting to a server. The variable will be expanded so it may contain environment variables. .IP "\s-1SHELL\s0 (string)" 4 .IX Item "SHELL (string)" The name of the shell to be used to execute pipes and to be used by the \&\fB\eshell\fR command (default '/bin/sh'). .IP "statistics (boolean)" 4 .IX Item "statistics (boolean)" Setting \fB\f(CB$statistics\fB\fR to 1 causes timing statistics to be displayed upon the successful execution of every batch of \s-1SQL\s0. This variable may also be set via the \fB\-p\fR command line flag, or by supplying \fB\-p\fR to the \fB\ego\fR command. \&\fB\f(CB$statistics\fB\fR defaults to 0. .IP "style (string)" 4 .IX Item "style (string)" Selects result set display style. Currently eight styles are supported. The \&\fBhoriz\fR (which may also be defined as \fBhor\fR or \fBhorizontal\fR), closely resembles the output of isql, with the traditional columnar output. .Sp The \fBvert\fR (or \fBvertical\fR) style rotates the output, so that every line is represented by a column name followed by a column value. This is nice for looking at particularly wide output. .Sp The \fBbcp\fR style displays results in a format amenable to bcp'ing the result set back into another table. That is, every column value is separated by \&\fB\f(CB$bcp_colsep\fB\fR with the final column separated by \fB\f(CB$bcp_rowsep\fB\fR followed by a newline (\en). If \fB\f(CB$bcp_colsep\fB\fR or \fB\f(CB$bcp_rowsep\fB\fR are not defined then '|' is used as the default separator. Note that this output does not work well with \&\s-1COMPUTE\s0 columns, and uses the default conversion methods for all data types (that is, \fBdatetime\fR columns may truncate the millisecond). .Sp The \fBcsv\fR display style outputs all result sets in the form of a comma separated construct. This mode is ideal to import result sets into spreadsheet programs, for instance. .Sp The \fBhtml\fR display style outputs all result sets in the form of an \s-1HTML\s0 <\s-1TABLE\s0> construct. This mode is ideal for the use of sqsh as a \s-1CGI\s0 application. .Sp The \fBmeta\fR display style outputs only the meta-data information associated with the result and discards the actual row results. This mode is useful for debugging the result sets generated from a full passthru Open Server gateway, or for those interested in what is really coming back from the server. .Sp The \fBpretty\fR display style generates a fluffy table-like output using regular \&\s-1ASCII\s0 characters for borders. This mode does not perform any explicit column wrapping, like the \fBhoriz\fR display mode. However, the \fB\f(CB$colwidth\fB\fR variable can be used to control the maximum width of a given column on the screen. If the column exceeds \fB\f(CB$colwidth\fB\fR characters wide, it is wrapped in a relatively visually appealing manner. Note that \fB\f(CB$colwidth\fB\fR may be exceeded if there is enough screen width to hold the columns without wrapping. .Sp The \fBnone\fR display style suppresses all results from being displayed (however it does actually retrieve result information from the \s-1SQL\s0 Server). This is particularly useful when used with the \fB\-p\fR flag (or the \fB\f(CB$statistics\fB\fR variable) for gathering accurate performance statistics. .IP "term_title (string)" 4 .IX Item "term_title (string)" When this variable is set, sqsh will reset the name of the current terminal (xterm) window it is running in. Works for xterm, rxvt, putty and MS-Windows \s-1CMD\s0 windows. The name consists of the sqsh startup name appended with the expanded value of the \fB\f(CB$term_title\fB\fR variable. .IP "thresh_display (int)" 4 .IX Item "thresh_display (int)" Sets the minimum \s-1SQL\s0 Server error severity that will display a message to the user, the default is 0 and valid ranges are between 0 and 22, inclusive. .IP "thresh_exit (int)" 4 .IX Item "thresh_exit (int)" Defines the maximum number of errors of severity level \fB\f(CB$thresh_fail\fB\fR that may be encountered before sqsh aborts. This is useful primarily for non-interactive scripts, but is allowed on an interactive session. Setting \fB\f(CB$thresh_exit\fB\fR to a value of 0 disables this feature. See section \fB\s-1EXIT\s0 \s-1STATUS\s0\fR for details. .IP "thresh_fail (int)" 4 .IX Item "thresh_fail (int)" Sets the minimum \s-1SQL\s0 Server severity level that is to be considered a failed batch. The minimum for this value is 0 (meaning any error that is not an information message), and the maximum is 22. Whenever \fB\f(CB$thresh_fail\fB\fR is crossed, the variable \fB\f(CB$batch_failcount\fB\fR is incremented by 1. See section \&\fB\s-1EXIT\s0 \s-1STATUS\s0\fR for details. .IP "time (date-spec)" 4 .IX Item "time (date-spec)" This variable may be set with a time format (see the man page for \fB\f(BIdate\fB\|(1)\fR), and the variable expands to the current time in the supplied format. The default format for this variable is \f(CW%H:\fR%M:%S (e.g. 14:32:58). .IP "timefmt (date-spec)" 4 .IX Item "timefmt (date-spec)" This variable may be set with a time format similar to \fB\f(CB$time\fB\fR and is used to control the display format of all \s-1SQL\s0 Server \s-1TIME\s0 and \s-1BIGTIME\s0 columns. (Similar to \fB\f(CB$datetime\fB\fR.) Note that only 63 bytes are available in total for the expanded string and the remainder will be truncated. .IP "tmp_dir (path)" 4 .IX Item "tmp_dir (path)" This contains the directory to which temporary files used internally by \fIsqsh\fR are to be written. These files are generated either during buffer editing (the \&\fB\ebuf\-edit\fR command), or to maintain output defer files for background jobs. The default value for this variable is /tmp. .IP "usedbcheck (boolean)" 4 .IX Item "usedbcheck (boolean)" When this variable is set to 'On' (default is 'Off') and a database name is provided with the \-D parameter and sqsh is run in batch mode, i.e. non-interactive, then a check will be performed if the specified database is accessible, otherwise sqsh is aborted with exit code 254. Also the following error message will be shown: .Sp \&\fBsqsh: \s-1ERROR:\s0 Unable to use database '...' in batch mode\fR .Sp This is to prevent that a \s-1SQL\s0 script is inadvertently executed in the wrong database, usually the default database of the login (master for example). .IP "username (string)" 4 .IX Item "username (string)" The name of the user currently connected to the database. .IP "version (none)" 4 .IX Item "version (none)" This read-only variable contains the current version number. (sqsh\-2.1.7) .IP "width (int)" 4 .IX Item "width (int)" The current width of the \s-1SQL\s0 output. .IP "xgeom (string/int)" 4 .IX Item "xgeom (string/int)" If X11 support is compiled into \fIsqsh\fR, this value is used to configure the default window size (in characters) of the X display. This variable must be of the format \fBWxH\fR or just \fBW\fR, where \fBW\fR is the width of the window and \fBH\fR is the height of the window. If the height of the window is not supplied, then 25 lines is assumed. If \fB\f(CB$xgeom\fB\fR is not set, then \fB\f(CB$width\fB\fR is used as the default width and the height is assumed to be 25. If neither is set, then 80x25 is assumed. .IP "xwin_title (string)" 4 .IX Item "xwin_title (string)" If X11 support is compiled into \fIsqsh\fR and an X11 result windows is requested by using the \fB\-x\fR parameter of the \fI\ego\fR or \fI\erpc\fR commands, then this variable will be used to set the title name of the window. Can be temporarily overridden with the \fB\-T\fR option of the \fI\ego\fR and \fI\erpc\fR commands. .SS "Script Execution" .IX Subsection "Script Execution" As with most shells, \fIsqsh\fR allows a file containing \s-1SQL\s0 and script commands to be executed directly via the magical \s-1UNIX\s0 \fB#!\fR convention. On most \s-1UNIX\s0 platforms, when the operating system encounters the bytes \fB#!\fR as the first two bytes of an executable file it will automatically pipe the file through the interpreter specified immediately after the \fB#!\fR. For example, to create an executable \fIsqsh\fR script to run \fBsp_who\fR, you simply need to create a file like so: .PP .Vb 3 \& #!/usr/bin/sqsh \-i \& sp_who \& go .Ve .PP Thus, if your \fBsp_who\fR script is executed directly, it will automatically launch "\fB/usr/bin/sqsh \-i sp_who\fR" for you. .PP And, to make things even more flexible, \fIsqsh\fR supports positional parameters, similar to most shells, of the form \fB${n}\fR which will expand to the \fBn\fRth argument to your \fIsqsh\fR script. For example: .PP .Vb 3 \& #!/usr/bin/sqsh \-i \& sp_who ${1} \& go .Ve .PP will cause the \fBsp_who\fR stored procedure to be executed with an argument of the first command line parameter supplied to the \fBsp_who\fR shell script. .PP Note that positional parameters \fImust\fR be contained between braces to avoid conflicts with the T\-SQL \fBmoney\fR data type (without the braces, the variable will not be expanded). .SH "EXIT STATUS" .IX Header "EXIT STATUS" One of the major complaints of \fIisql\fR is that it provides no facility to detect when an error condition occurred while it is performing processing. \fIsqsh\fR provides a rather complex, but flexible mechanism for returning meaningful information concerning its reason for exit in the form of an exit status (see \&\fB\f(BIexit\fB\|(3)\fR). .PP When \fIsqsh\fR begins execution two handlers are associated with the current connection to the database, one is a message handler which is responsible for displaying the text of any \s-1SQL\s0 Server messages or errors, and the other is an error handler, which is responsible for determining what to do with an error condition (bear with me, these are only loose descriptions). And, associated with each message and error condition is a severity level, between 0 and 22 (informational message to fatal condition). .PP Associated with these two message handlers are several variables that are used to either control their behavior, or are used as indicators by the message handler: .ie n .IP "$thresh_display" 4 .el .IP "\f(CW$thresh_display\fR" 4 .IX Item "$thresh_display" This variable is used by the message handler to determine the minimum error severity which will cause a message to be displayed. By default this is 0, which will display all messages (with a couple of exceptions). Setting this to 1, for example, would suppress informational messages such as the output of \&\fBset showplan on\fR. .ie n .IP "$thresh_fail" 4 .el .IP "\f(CW$thresh_fail\fR" 4 .IX Item "$thresh_fail" This variable is used by the error handler to determine which error severity is considered by \fIsqsh\fR to be a failure. Normally, this defaults to 11 which indicates that any error, other than informational messages, is a failure. The next variable will explain the importance of this value. .ie n .IP "$batch_failcount" 4 .el .IP "\f(CW$batch_failcount\fR" 4 .IX Item "$batch_failcount" This variable should be considered read-only, and contains the total number of times that batches have caused an error of severity \fB\f(CB$thresh_fail\fB\fR or more. The only value that is valid to explicitly set this value to, is "" (the empty string), which will reset this value to 0, any other value may have unpredictable results. .ie n .IP "$thresh_exit" 4 .el .IP "\f(CW$thresh_exit\fR" 4 .IX Item "$thresh_exit" This variable is used to determine the limit at which \fB\f(CB$batch_failcount\fB\fR will cause \fIsqsh\fR to exit. If \fB\f(CB$thresh_exit\fB\fR is 0, then this feature is disabled. In other words, if \fB\f(CB$batch_failcount\fB = \f(CB$thresh_exit\fB\fR and \fB\f(CB$thresh_exit\fB\fR is greater than 0, then \fIsqsh\fR will exit, returning \fB\f(CB$batch_failcount\fB\fR as an exit status. .Sp Note that, unless \fB\f(CB$exit_failcount\fB\fR is set to 1, \fIsqsh\fR will exit with 0 if the total number of failures does not reach \fB\f(CB$thresh_exit\fB\fR. .ie n .IP "$exit_failcount" 4 .el .IP "\f(CW$exit_failcount\fR" 4 .IX Item "$exit_failcount" This variable is used only when \fIsqsh\fR would normally exit with a success status (0), this causes it to instead exit with a value of \fB\f(CB$batch_failcount\fB\fR (which may, itself, be 0). .ie n .IP "$exit_value" 4 .el .IP "\f(CW$exit_value\fR" 4 .IX Item "$exit_value" When this variable is non-zero, it will override the \fB\f(CB$exit_failcount\fB\fR and \&\fB\f(CB$batch_failcount\fB\fR values and just exit the value of \fB\f(CB$exit_value\fB\fR. This variable may be explicitly set using the \fB\eset\fR command, or implicitly using \&\fB\eexit x\fR and its aliased counterparts. .PP To recap, here is a list of error codes that may be returned by \fIsqsh\fR upon exit, and the reason that they could be returned: .IP "\- 0 \-" 4 .IX Item "- 0 -" No error has been encountered. .IP "\- 1...253 \-" 4 .IX Item "- 1...253 -" Between 1 and 253 batches have failed (if you run more than 253 batches, the exit status of sqsh is undetermined...I may fix this in the future). .IP "\- 254 \-" 4 .IX Item "- 254 -" An explicit \fB\eabort\fR was called, or a \s-1SIGINT\s0 (^C) was issued during a non-interactive session. .IP "\- 255 \-" 4 .IX Item "- 255 -" A general error condition has occurred, such as a bad command line argument to sqsh, memory allocation failure, file access error, etc. .PP The following sections provide detailed examples of combinations of variable settings and the results produced upon exit with certain failure conditions. It is assumed the \fB\f(CB$exit_value\fB\fR variable contains 0 in the next examples. .IP "thresh_display=0, thresh_fail=0, thresh_exit=1" 4 .IX Item "thresh_display=0, thresh_fail=0, thresh_exit=1" With this combination, all error messages will be displayed as they happen, and every error will be considered an failure condition. Upon reaching the first error, \fIsqsh\fR will abort with an exit status of 1, or the total number of failures (the \fB\f(CB$batch_failcount\fB\fR variable). However, if nothing goes wrong during the whole process, a zero is returned. .IP "thresh_display=0, thresh_fail=0, thresh_exit=3" 4 .IX Item "thresh_display=0, thresh_fail=0, thresh_exit=3" This combination will cause all error conditions to be displayed and all of them to be considered a failure condition. Upon reaching three total failed batches, \&\fIsqsh\fR will exit with a status of 3. However if 0, 1, or 2 batches fail, then 0 is returned. .IP "thresh_display=22, thresh_fail=0, thresh_exit=3" 4 .IX Item "thresh_display=22, thresh_fail=0, thresh_exit=3" This behaves the same as the previous example, with the exception that all error messages will be suppressed from being displayed. This is particularly useful if you just care about the exit value more than the actual error. .IP "thresh_display=0, thresh_fail=2, thresh_exit=1" 4 .IX Item "thresh_display=0, thresh_fail=2, thresh_exit=1" This will cause the first error of severity 2 or higher to be displayed and cause \fIsqsh\fR to exit with a failure condition of 1. .IP "thresh_display=0, thresh_fail=0, thresh_exit=3, exit_failcount=1" 4 .IX Item "thresh_display=0, thresh_fail=0, thresh_exit=3, exit_failcount=1" This is identical to the second example, above, however \fBsqsh\fR will return the total number of batches that failed even if \fB\f(CB$batch_failcount\fB\fR does not reach 3. .IP "exit_value=nonzero" 4 .IX Item "exit_value=nonzero" This will override all conditions explained above and just exit the specific value. .SH "MISCELLANEOUS" .IX Header "MISCELLANEOUS" .SS "Colorizing sqsh prompts" .IX Subsection "Colorizing sqsh prompts" Color codes are presented as a string like {1;2;3}. If sqsh encounters a { (curly brace) in the prompt string it will assume a color-code is supplied and will act as such. No checks will be performed on the validity of the color-code definition itself. The color definition consists of three values separated by a semicolon. .PP The first code defines the Color Attribute Code with possible values: 0=none 1=bold The second value defines the Text Color Code: 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white The third value defines the Background Color Code: 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white The last color-code for the background may be omitted. Not all color and attribute combinations will present good results, depending on your terminal type and color scheme. But the following values work \s-1OK\s0 on a xterm with a creamy white background color in Linux as well as rxvt in Cygwin with a black background window: .PP .Vb 3 \& Prompt: Blue text in white background "{0;34;47}" \& Command text: Yellow text "{0;33}" \& Command text: Default text color "{0}" .Ve .PP sqsh will translate the color-codes to an actual color-code string that is presented to readline: for example \*(L"\e001\e033[0;36;47m\e002\*(R". Note that if you want to use curly brackets in your prompt, you have to escape colorization by specifying a double brace, like {{...}}. For example: .PP .Vb 3 \& \eset prompt_color=\*(Aq{0;34;47}\*(Aq \& \eset text_color=\*(Aq{0}\*(Aq \& \eset prompt=\*(Aq$prompt_color{{$DSQUERY.$username.$database.$lineno}}>$text_color \*(Aq .Ve .PP Color support is automatically available if sqsh is compiled and linked with readline support enabled. .SH "FILES" .IX Header "FILES" Defaults: \f(CW$HOME\fR/.sqshrc, \f(CW$HOME\fR/.sqsh_session, \f(CW$HOME\fR/.sqsh_history, \&\f(CW$HOME\fR/.sqsh_readline, \f(CW$HOME\fR/.sqsh_words, \f(CW$tmp_dir\fR/sqsh\-dfr.*, \&\f(CW$tmp_dir\fR/sqsh\-edit.* These can all be modified using the internal \fIsqsh\fR variables described above. .SH "BUGS" .IX Header "BUGS" The addition of flow-of-control expressions has extended sqsh \fIway\fR beyond the scope of its original design, and it is quite obvious from using the features they are hacked in and are rather clunky (although still quite usable). As a result, the processing of these expressions is rather slow (when compared to bourne shell), and the error reporting doesn't lend itself to debugging large scripts. The development of 1000+ line scripts is discouraged. .PP The combination of backgrounding and pipes does not work properly right now. What happens is, when a background job is run that incorporates a pipe-line, \&\fIsqsh\fR will suspend until the job is complete, which is obviously not what you desire. To test this, try the following: .PP .Vb 2 \& 1> select * from syscolumns \& 2> go | grep id & .Ve .PP You will find that you do not get your prompt back until the job completes. The same is more ore less true for pipes being used with the \edo command: .PP .Vb 2 \& 1> select name from master..sysdatabases \& 2> \edo | grep syb .Ve .PP This will not give you a prompt anymore until the block completes with \edone. So you are typing the do block itself in the dark and there is no possiblity to edit a do block or retrieve a do block from the history list. So you may have typed (hopefully without syntax errors): .PP .Vb 2 \& \eecho #1 \& \edone .Ve .PP After \edone is processed the results will be displayed followed by a fresh prompt. .PP Please report any other bugs to http://sourceforge.net/p/sqsh/bugs Feature requests may be posted to http://sourceforge.net/p/sqsh/feature\-requests