Saturday, June 03, 2006

sqlpython enhancements

I told you that Luca Canali's sqlpython is wonderfully easy to customize.

I probably should have also told you that it's dangerously addictive to customize. I kind of went out of control, and produced, a module of enhancements to sqlpython.

- SQL*Plus-style bind variables
- Query result stored in special bind variable ":_" if one row, one item
- SQL buffer with list, run, ed, get, etc.; unlike SQL*Plus, buffer stores session's full history
- @script.sql loads and runs (like SQL*Plus)
- ! runs operating-system command
- SQL*Plus-style describe, spool
- write sends query result directly to file
- comments shows table and column comments
- compare ... to ... graphically compares results of two queries
- commands are case-insensitive
- show and set to control sqlpython parameters is not as clean and elegant as sqlpython - that's one reason I put it in a separate module, so that you can keep it separate from the original sqlpython and your own homemade enhancements. But it should cover pretty much everything you usually use SQL*Plus for, plus some goodies I hope you'll like.

[EDIT: Since I wrote this, Luca has wrapped an enhanced and debugged version of sqlpyplus into his distribution of sqlpython itself. Now you should simply go and get or upgrade sqlpython, and you'll have these goodies automatically.]


Anonymous said...

Great! I have just integrated into the current version of mysqlpy.

Cheers, Luca

Tim said...


Can it be made to display some of a clob in the results?

At the moment it chokes:

ProgrammingError: LOB variable no longer valid after subsequent fetch

Traceback (innermost last):

File "c:\Python25\Lib\site-packages\sqlpython\", line 1, in module
# MySqlPy V1.2
File "c:\Python25\Lib\site-packages\sqlpython\", line 180, in module
File "c:\Python25\Lib\", line 142, in cmdloop
stop = self.onecmd(line)
File "c:\Python25\Lib\", line 219, in onecmd
return func(arg)
File "c:\Python25\Lib\site-packages\sqlpython\", line 368, in do_select
print '\n' + sqlpython.pmatrix(self.rows,self.desc)
File "c:\Python25\Lib\site-packages\sqlpython\", line 104, in pmatrix
rowsi = map(str, rows[i]) # current row to process