H C   S O F T W A R E   L T D

commanderbond cryptosaurus image jdep spambuddy superstopwatch textscape textscape2 utilities xmogrify xql yago

download

requires java 1.5+

licensed under the GPL license

  1. download the distribution
  2. unzip somewhere
  3. cd to the created directory, run: java -jar xql.jar

XQL SQL client

XQL Is a JDBC-based SQL client. It is different from most in that it is stateless. Each invocation creates a database connection, executes some SQL and exits. This makes it convenient to use inside another shell or terminal programme. It can also make it very slow. For example:

java -jar xql-0.2/xql.jar --presetfile .xql/presets.properties --cp jconn2.jar -p database1 "sp_tables 'nl%',null,'loanx'" | less
Executes the stored procedure sp_tables (using the driver in jconn2.jar) and pipes the result to less for viewing one screenful at a time.

java -jar xql-0.2/xql.jar --presetfile .xql/presets.properties --cp driver.jar -p database2 "select * from all_tables" | grep mytable
Selects all the rows from all_tables and pipes the result to grep which prints out any lines containing the string 'mytable'.

java -jar xql.jar "select * from employees" | grep bloggs > bloggss

usage notes

For each usage you need to supply values for: JDBC URL, driver, username, password
You can either provide these as options, or store them in a presets file and refer to them by name using the --preset option.

Sample presets.properties file: save this as ${HOME}/.xql/presets.properties; or specify another location using the --presetfile option.

XQL will need access to the JDBC driver classes provided by your database vendor. You supply the name of the main driver class using the --driver option, XQL will need to find this class. There are 2 ways you can provide the class to XQL:

  1. put the class/jar in the java classpath (e.g. by suppling a -cp option to java)
  2. use XQL's --cp option to set an 'extra' classpath that is searched in addition to the System classpath. For Example:
  3. java -jar xql.jar --cp driver.jar:driver2.jar --driver com.foo.db.Driver ...
    loads com.foo.db.Driver by scanning driver.jar and driver2.jar in addition to the regular system classpath

ChangeLog

October 2009
Use executeBatch() in copytable if --force option not set. (much faster)
Use ps.setDouble(..) meths instead of setObject (on SQL server was not preserving the precision, so Double was getting rounded on copy. Uses dedicated meths now for most recognisable types (Double,Float,Int,Varchar etc.).
September 2008
Can put surround values in presets.properties with double-quote characters, in which case commas inside them are ignored. This allows (for example) connection strings that contain commas to be used.
January 2008
Bugfix: --listpresets now works
September 2007
Bugfix: --copytable used to ignore the final column of a table - no longer does this
April 2007 version 0.24
Modified so can leave password/name empty in .xql/presets.properties and it will be treated as the empty string ("").
Jan 2007 version 0.23
March 2006 version 0.22
Now supports queries which return multiple resultsets (prints one out after another). Also, if query updates DB, prints out update count, rather than reporting an error. (e.g. don't have to use the -u flag - though it may be marginally faster if you do so.
Feb 2006 version 0.21
fixed bug where --scriptfile arg not working
Oct 2005 (version 0.2 -- not backwards compatible)
Summer 2003 version 0.1
Ported to Java and made improvements, such as configurable formatting of results and update queries
Summer 2003
First created python script for executing SQL queries using JDBC

Notes

Sybase

Data dictionary example: select t.name,c.name from sysobjects t,syscolumns c where c.id=t.id and t.type='U' order by t.name,c.colid (thanks to SB)