SourceForge.net Logo

Please note that this documentation is out of date. It will be updated soon!

Have you ever wanted to just run a quick sql command from the command line? Ever been distracted by having to load a memory intensive gui application? Ever think 'wow - it'd be great to just run this sql statement from my text editor'?? If so then read on...

Sqelsh is a command line interface for JDBC enabled databases. It is easy to set up and use and just runs instantaneously... You can connect to several different databases within a session and switch between them easily by specifying the url of the database.

You can even pipe input from another command and redirect output to a file if you wish!

Latest

Sqelsh 1.2(RC1) is available.

06/06/2008

Changes

  • Removed JLine dependency (too slow)
  • Queries are now run in a separate thread so that long running queries may be cancelled by pressing RETURN key.
  • Removing the need for SQELSH_HOME environment variable so the application can be loaded and run on a flash drive.

TODO

  • Update documentation
  • Add command to close a connection - Previously, the program cached all connections until termination.
  • Add alias mechanism to properties file.
  • Add an optional auto update notifier.
Download

25/04/2008 sqelsh-core-1.0.1.jar released. Fixes problem with redirected input.

24/04/2008 sqelsh-meta-plugin-1.0.1.jar released to fix a bug. Download

Features

  • Runs on the command line.
  • Maintains command history.
  • Caches connections by url.

Screenshots

In cygwin:

and in cmd.exe

Installation

Download and extract a package from sqelsh-package.

Create an environment variable called SQELSH_HOME with the location of the extracted directory as its value.

Add the following to your CLASSPATH:

25/04/2008 corrected classpath: $SQELSH_HOME/sqelsh-1.0.jar;$SQELSH_HOME/lib/plugin-core-1.0.jar;$SQELSH_HOME/lib/cli-annotations-1.0.jar; $SQELSH_HOME/lib/commons-cli-1.1.jar;$SQELSH_HOME/lib/jline-0.9.94.jar;$SQELSH_HOME/lib/log4j-1.2.14.jar;

Linux users need a colon instead of a semi-colon though - and the notation for an environment variable is different...

Also, put the location of the jar containing your database JDBC driver into your system environment variable CLASSPATH.

Put the class name of your driver into an environment variable or system property called jdbc.drivers.

Edit the sqelsh.properties (see Properties) file to reflect your default connection settings and put it in your home directory.

If you need help, please post a message on the forum.

Updates

When an update is released, it can replace the original jar. If it is a core jar, you will have to update your CLASSPATH variable accordingly because the version number is likely to change.

Plugins

Plugins reside in the plugins directory under SQELSH_HOME. They are loaded at runtime and don't need to be referenced in the classpath. If a new plugin is released, simply download it and place it here. It will be loaded the next time you start the program.

Running it!

The program is designed to be run in a command shell, so your shell window's width will have to be quite large in order to display the output in a legible format.

To run it, type java ie.potz.Sqelsh -i at the command prompt.

You will be prompted with sql:

So now you can enter sql statements or internal sqelsh commands. SQL should be terminated with a semi-colon. Type quit to exit the program.

Properties

Sqelsh examines the working directory for a file called sqelsh.properties. If it can't find one, it tries the user's home directory. The following properties may be set in the properties file as key-value pairs. A sample properties file is provided in the installation packages.

sqelsh.url JDBC URL for the database to connect to.

sqelsh.user Username to use for the connection.

sqelsh.pass Password for user

sqelsh.fetch Maximum fetch size - won't return more rows than this for a single query.

Command Line Arguments

Settings in the sqelsh.properties file may be overridden at the command line. The following flags may be set on the command line.

-u url JDBC URL for the database to connect to. This overrides property sqelsh.url

-U username Username to connect with. This overrides property sqelsh.user

-p password Password for connection. This overrides property sqelsh.pass

-s size ResultSet fetch size. This overrides property sqelsh.fetch

-i Interactive mode.

-v Verbose logging.

-h Display help.

-d Display connection url.

-l Long output for metadata commands.

-P table Primary key for table.

-x table Display indexes for table.

-t table Show column information for table.

-r table References for table.

-f table Foreign keys for table.

-D pattern List database tables matching pattern

Internal Sqelsh Commands

The following commands may be entered at any time at the 'sql:' prompt - even if you are in the process of entering sql. The statement will be lost however... All arguments are optional. The user will be prompted accordingly...

/u url Connect to database defined by url.

/d display current url

/U username Username to use when connecting to the database. This overrides property sqelsh.user. Will prompt for username if not provided.

/p password for connection. Overrides property sqelsh.pass

/s size Fetch size. This overrides property sqelsh.fetch. Specifying a zero size or not specifying a size at all means return all rows.

/D pattern Show tables in current database. Enter /D % for all.

/t table Show table column information for table. Will prompt for table if not provided.

/x table Show indexes for table. Will prompt for table if not provided.

/f table Show table column information for table. Will prompt for table if not provided.

/P table Show primary key information for table. Will prompt for table if not provided.

/r table Show references for table. Will prompt for table if not provided.

/h Show help

/q Quit the program

FAQ

Can I use transactions?

Yes. You can start a transaction at any time. Connections are cached within the application, so you can even connect to a different database with the /u command and when you /u back to the original url, you will still be in the transaction.

How do I save output to a file?

I do it like this for short sql commands: echo select * from table;| java ie.potz.Sqelsh > myfile and like this for long sql commands: cat file.sql | java ie.potz.Sqelsh > filename.unl

How do I run it from vi?

Good question... Something to do with :r and creating a custom command... please let me know!

I need help!

email me at the address below.

Links

Sqelsh uses these open source projects:

commons-logo

commons-logo

So thats it! More technical information and javadocs to follow soon. If you like or dislike Sqelsh or would like to see something added, please leave a message in the forum or email me potzie at users.sourceforge.net.