SQLite Shell written in Jim TCL
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


    jSQLsh - Jim Tcl SQLite Shell

    jsqlsh [Options] [--] <Database File>

    jSQLsh is an SQLite shell based on the PostgreSQL command line shell.
    Implemented using the Jim Tcl interpreter. It is intended to be a simple
    light weight SQLite shell. The ReadLine library in Jim Tcl is used to
    provide line editing and history. History persists in the file

    jSQLsh is not compatible with the sqlite3 command line client. It does
    not recognize any of the sqlite3 *.* commands. In fact by default jSQLsh
    does not execute SQL, even with an ending *;*. You have to tell jSQLsh
    when to execute the contents of the query buffer, or turn on auto mode.
    I tried to make configuration easy via the /set command.

    There are things about the SQLite command shell that annoy me. Since I
    could not find any easily modified, decent, command line SQL clients, so
    I wrote my own. This is also my first foray in TCL programming.

    -a          Enable execution of queries ending with ';'. (auto setting)

    -c          Create the database file. Fails if the file exists. Normally
                jSQLsh will not open a database file that does not exist

    -d          Disable slash commands and enable auto execution. Makes
                jsqlsh act like a dumb SQL evaluator.

    -D          Debug mode. (Copious output!)

    -h          Display the help text.

    -q          Set quiet mode.

    -s'opt=val' Set an option as in the '/s' command.

    --          Stops processing command line options. The next option is
                used as the database file to open.

    The prompt displays several bits of useful information. A typical prompt
    resembles DB.db (0 rows, 0 changes) #. The database name, number of rows
    returned from the last query, the number of rows changed by the last
    query and the prompt setting. When debugging is enabled the prompt will
    also have DEBUG as a reminder.

    jSQLsh has several commands for interactive use. These are patterned
    after the psql commands. All commands start with a forward slash "/".
    The parts in parens "()" are optional.

    /A(UTO)     Toggle the auto option state.

    /c(lear)    Clear the query buffer

    /D(EBUG)    Toggle the debug option state.

    /d          Display all objects in the database.

    /d\[itv\]   Display all indexes (/di) / tables (/dt) / views (/dv).

    /d OBJ      Describe the object OBJ.

    /ds OBJ     Displays the schema for the object OBJ.

    /e(dit)     Edit the query buffer. This uses the editor defined in
                *$EDITOR* or *vi*.

    /go or /    Execute the query in the query buffer..

    /h(elp)     Print this help text.

    /o(pen)     Open a database file, change directories and list files.
                */o* alone lists files in the current directory. */o DIR*
                changes to the directory *DIR*.

    /P(AGER)    Toggle the page option state. This uses the pager defined in
                *$PAGER* or *more*/

    /p(rint)    Print the query buffer.

    /s(et)      Set/List configuration options. The format to set options is
                */s OPTION VALUE*. Values are treated as TCL strings and can
                be quoted.

    /Q(UIET)    Toggle the quiet option state.

    /q(uit)     Quit (Also Ctrl-D)

    /u(ser)     Display the user macros.

    /u(ser)#    Copy user macro # into the query buffer. Replacing the
                current query buffer contents.

    /u(ser)# -  Copy the query buffer, or supplied text, into macro #.

    Settings are changed with the /s command as noted above. Each setting is
    either a text or boolean value.

    The values *1*, *true*, *yes* &, *on* count as true boolean values.
    Anything is considered false. Boolean settings are indicated by the text
    *Bool* after their description.

    auto        Automatically execute SQL ending with ';'. Defaults to off.

    debug       Controls debugging mode. (Very Verbose!) Defaults to off.

    editor      The editor program for editing queries. Defaults to either
                *$EDITOR* or *vi*. *Text*

    ext         SQLite file extension. Defaults to *.db*. *Text*

    escape      The escape character for CSV mode. Defaults to *\\*. *Text*

    header      If table headers should be printed. Defaults to on. *Bool*

    null        The value that represents SQL NULL. Defaults to *NULL*.

    page        Use the 'pager' program for long results. Defaults to on.

    pager       The pager program for long results. Defaults to either
                *$PAGER* or *more*. *Text*

    ps1         Main prompt. Defaults to *#*. *Text*

    ps2         More prompt. Defaults to *?*. *Text*

    quiet       Disables informational messages. Defaults to off. *Bool*

    quote       The quote character for CSV mode. Defaults to *"*. *Text*

    sep         Field separator for CSV & List modes. Defaults to *,*.

    trunc       Truncate long rows to fit the screen. Defaults to off.

    During startup, before command line options are processed, the
    configuration file ~/.jsqlshrc is read. This file can contain any
    commands as noted above. Comments denoted by # and whitespace are
    ignored. SQL queries will not work.

    jSQLsh should work with any recent version of Jim Tcl (7 and later
    should be good). Jim needs to be compiled with at least the modules
    readline and sqlite3. Thus far testing has only been performed under
    Cygwin and Debian Linux "Squeeze".


    Either copy jsqlsh where you want it or run *make install*. The makefile
    will copy jsqlsh and the manual page to */usr/local/*. Edit the makefile
    to choose a different location.


    These files are in the public domain.

    Written by Jessica K McIntosh ATL gmail DOT com

    I welcome any input.