NAME
isql, iusql - unixODBC interactive SQL command-line tools
SYNOPSIS
isql DSN [USER [PASSWORD]] [options]
iusql DSN [USER [PASSWORD]] [options]
iusql "ConnectionString" [options]
DESCRIPTION
isql and iusql are command-line tools allowing users to execute SQL interactively or in batches.
The tools provide several useful features, including an option to generate output wrapped in an HTML table.
iusql is the same as isql but includes built-in Unicode support. Some data sources only work with iusql. An important difference between the two tools is that isql connects using SQLConnect and iusql connects using SQLDriverConnect.
ARGUMENTS
DSN |
The Data Source Name (DSN) used to connect to the SQL database. unixODBC looks for the specified DSN in /etc/odbc.ini and $HOME/.odbc.ini, with the latter taking precedence. |
When searching the configuration files, unixODBC looks for a bare name. If the DSN begins with a semicolon, it is treated as a connection string. The connection string can contain a DSN and/or other semicolon-separated parameters.
USER |
Specifies the database user or role under which the connection should be made. |
This parameter overrides any UID specified in the data source configuration files.
PASSWORD
Password required to access the database for the specified USER.
This parameter overrides any PASSWORD specified in the data source configuration files.
When using iusql, passwords containing semicolons should be escaped with braces (curly brackets) and terminated with a semicolon. Refer to the Examples section below for syntax.
"ConnectionString"
A connection string starting with DSN=, DRIVER= or FILEDSN= will be passed unchanged to SQLDriverConnect. This option allows for the use of more complex syntax in a connection string than would otherwise be possible by just using DSN, UID and PWD.
It also (and this was the main reason for its inclusion) allows passwords to contain semicolons without having to add complex escape syntax to the existing code.
OPTIONS
-b |
Run ’isql’ in non-interactive batch mode. In this mode, ’isql’ processes from standard input, expecting one SQL command per line. |
-dDELIMITER
Delimit columns with the specified delimiter.
-xHEX |
Delimit columns with the character represented in hexadecimal by HEX. The hexadecimal code must be in the format 0xNN (e.g. 0x09 for the TAB character). | ||
-w |
Format the result as an HTML table. | ||
-c |
Output the names of the columns on the first row. This option can only be used with the -d or -x options. | ||
-mNUM |
Limit the column display width to NUM characters. |
-lLOCALE
Set the character locale to LOCALE.
-q |
Wrap the character fields in double quotes. | ||
-3 |
Use calls from ODBC version 3. | ||
-n |
Process multiple lines of SQL, terminated with the GO command. | ||
-e |
Use SQLExecDirect instead of Prepare. | ||
-k |
Use SQLDriverConnect. | ||
-v |
Enable verbose mode, fully describing all errors. This option is useful for debugging. |
--version
Display the program version.
-LNUM |
Set the maximum number of characters displayed from a character field to NUM. The default value is 300 characters. |
COMMANDS
This section briefly describes some isql and iusql run-time commands.
help
List all tables in the database.
help table
List all columns in the table.
help help
List all help options.
EXAMPLES
A bare DSN:
$ iusql WebDB MyID MyPWD -w -b < My.sql
Connects to the WebDB DSN as user MyID with password MyPWD, then executes the commands in the My.sql file and returns the results wrapped in an HTML table.
Each line in My.sql must only contain one SQL command, except for the last line, which must be blank (unless the -n option is specified).
A DSN in a connection string:
Note the leading semicolon on the connection string.
$ iusql ";DSN=WebDB" MyID MyPWD -w -b < My.sql
Options in the DSN may be overridden in the connection string:
$ iusql ";DSN=WebDB;Driver=PostgreSQL ODBC;UID=MyID;PASSWORD=secret;Debug=1;CommLog=1" -v
A string DSN:
A string DSN may be provided in its entirety, with no file DSN reference at all:
$ iusql ";Driver=PostgreSQL Unicode;UID=MyID;PASSWORD=secret" -v
A password containing a semicolon (iusql):
$ iusql WebDB MyID ’{My;PWD};’
$ iusql ’DSN=WebDB;UID=MyID;PWD={My;PWD};’
TROUBLESHOOTING
Cryptic error messages
Re-run isql or iusql with the -v flag to get more information from errors, and/or enable Trace mode in odbcinst.ini.
Missing driver definition
Check that the driver name specified by the Driver entry in the odbc.ini data-source definition is present in odbcinst.ini and exactly matches the odbcinst.ini [section name].
Unloadable or incompatible driver
If the ODBC driver is properly specified for the data source, it is possible that the driver is not loadable. Check for mix-ups between Unicode and ANSI drivers, and verify the driver paths in the odbcinst.ini [section name].
Unicode data sources with ANSI clients
Some data
sources are Unicode-only and require the use of
iusql. If isql reports
[IM002][unixODBC][Driver Manager]Data source name not found
and no default driver specified
[ISQL]ERROR: Could not SQLConnect
but the data source and driver required are listed by
odbcinst -q -d
and
odbcinst -q -s
then try iusql.
FILES
/etc/odbc.ini
Configuration file containing system-wide Data Source Name (DSN) definitions. See odbc.ini(5) for more information.
$HOME/.odbc.ini
Configuration file containing user-specific Data Source Name (DSN) definitions. See odbc.ini(5) for more information.
SEE ALSO
unixODBC(7), odbcinst(1), odbc.ini(5)
"The unixODBC Administrator Manual (HTML)"
AUTHORS
The authors of unixODBC are Peter Harvey <pharvey [AT] codebydesign.com> and Nick Gorham <nick [AT] lurcher.org>.
For a full list of contributors, refer to the AUTHORS file.
COPYRIGHT
unixODBC is licensed under the GNU Lesser General Public License. For details about the license, see the COPYING file.