# HG changeset patch # User catherine@localhost # Date 1212085255 14400 # Node ID 4aa28dffe658c9eee255fa95d326d1acd55bbefc # Parent c5f601abc993f1a9b332c2b3387a05ae9a49178a command-line args working well diff -r c5f601abc993 -r 4aa28dffe658 README.txt --- a/README.txt Thu May 29 13:14:06 2008 -0400 +++ b/README.txt Thu May 29 14:20:55 2008 -0400 @@ -30,6 +30,71 @@ Read the help. Experiment with UNIX-style and postgresql-style commands. +Special output (inspired by YASQL) +---------------------------------- + +An integer following a command terminator limits output to that number of rows, like SQL's LIMIT keyword:: + + hr@xe> SELECT * FROM jobs;2 + +If `;` is replaced by one of these special characters, the output will be formatted as such:: + +---------- ---------------------- +terminator format +---------- ---------------------- +; standard Oracle format +\c CSV (with headings) +\C CSV (no headings) +\g list +\G aligned list +\h HTML table +\i INSERT statements +\s CSV (with headings) +\S CSV (no headings) +\t transposed +\x XML +---------- ---------------------- + +Special terminators can also be combined with row limits:: + + hr@xe> SELECT * FROM jobs\h5 + +Redirecting output +------------------ + +`>` and `>>` write or append the output of a command. If a +filename is given, that will be the destination of the output. + +If no filename is given, the output will go into the paste buffer and +can immediately pasted to any program. This requires `xclip` (*nix) or +`pywin32` (Windows) to be installed on the operating system. + +Connecting +---------- + +sqlpython supports every version of connecting that SQL*Plus does, including EZCONNECT:: + + $ > sqlpython + $ > sqlpython hr/hr@xe + $ > sqlpython hr (uses ORACLE_SID, prompts for password) + $ > sqlpython hr/hr@hostmachine.somewhere.com/xe + $ > sqlpython hr/hr@hostmachine.somewhere.com:1521/xe + $ > sqlpython sys@xe as sysdba + +You may also supply commands that will be run immediately after connection:: + + $ > sqlpython hr/hr@xe @myscript.sql @another_script.sql quit + +Multi-word commands must be enclosed in double-quotes:: + + $ > sqlpython hr/hr@xe "cat jobs" "select * from employees;" + +Combining special output terminators with redirectors and command-line arguments +can produce powerful one-line programs. For instance, this generates an HTML +report and exits:: + + $ > sqlpython hr/hr@xe "select * from jobs\h > jobs.html" quit + Modifying --------- diff -r c5f601abc993 -r 4aa28dffe658 mysqlpy.py --- a/mysqlpy.py Thu May 29 13:14:06 2008 -0400 +++ b/mysqlpy.py Thu May 29 14:20:55 2008 -0400 @@ -1,5 +1,5 @@ #!/usr/bin/python -# MySqlPy V1.3 +# MySqlPy V1.4.6 # Author: Luca.Canali@cern.ch # # @@ -13,9 +13,9 @@ class mysqlpy(sqlpyPlus): ''' -MySqlPy V1.3 - 'sqlplus in python' +MySqlPy V1.4.6 - 'sqlplus in python' Author: Luca.Canali@cern.ch -Rev: 1.4.4, 28-May-08 +Rev: 1.4.8, 29-May-08 Companion of SqlPython, a python module that reproduces Oracle's command line within python and sqlpyPlus. Major contributions by Catherine Devlin, http://catherinedevlin.blogspot.com @@ -168,9 +168,18 @@ print my.__doc__ try: if sys.argv[1][0] != '@': - my.do_connect(sys.argv.pop(1)) + connectstring = sys.argv.pop(1) + try: # attach AS SYSDBA or AS SYSOPER if present + for connectmode in my.connection_modes.keys(): + if connectmode.search(' %s %s' % tuple(sys.argv[1:3])): + for i in (1,2): + connectstring += ' ' + sys.argv.pop(1) + break + except TypeError: + pass + my.do_connect(connectstring) for arg in sys.argv[1:]: - if my.onecmd(arg, assumeComplete=True) == my._STOP_AND_EXIT: # ugh, filename gets ; appended + if my.onecmd(arg, assumeComplete=True) == my._STOP_AND_EXIT: return except IndexError: pass diff -r c5f601abc993 -r 4aa28dffe658 setup.py --- a/setup.py Thu May 29 13:14:06 2008 -0400 +++ b/setup.py Thu May 29 14:20:55 2008 -0400 @@ -9,7 +9,7 @@ Operating System :: OS Independent""".splitlines() setup(name="sqlpython", - version="1.4.5", + version="1.4.6", description="Command-line interface to Oracle", long_description="Customizable alternative to Oracle's SQL*PLUS command-line interface", author="Luca Canali", diff -r c5f601abc993 -r 4aa28dffe658 sqlpython.py --- a/sqlpython.py Thu May 29 13:14:06 2008 -0400 +++ b/sqlpython.py Thu May 29 14:20:55 2008 -0400 @@ -1,7 +1,7 @@ # -# SqlPython V1.3 +# SqlPython V1.4.6 # Author: Luca.Canali@cern.ch, Apr 2006 -# Rev 18-Oct-07 +# Rev 29-May-08 # # A python module to reproduce Oracle's command line 'sqlplus-like' within python # Intended to allow easy customizations and extentions