# HG changeset patch # User catherine@Elli.myhome.westell.com # Date 1229613027 18000 # Node ID ed46f2dba929b1fb74a7a3eac5cfbd9bb8dced00 # Parent 1c3df79fd088f898f01bcb4ddfb71066c2bc1dc1 fixed sessinfo diff -r 1c3df79fd088 -r ed46f2dba929 sqlpython/mysqlpy.py --- a/sqlpython/mysqlpy.py Fri Dec 12 10:14:09 2008 -0500 +++ b/sqlpython/mysqlpy.py Thu Dec 18 10:10:27 2008 -0500 @@ -9,7 +9,7 @@ # http://catherine.devlin.googlepages.com/ from sqlpyPlus import * -import binascii, sys, tempfile, optparse, unittest +import sys, tempfile, optparse, unittest class mysqlpy(sqlpyPlus): ''' @@ -121,9 +121,8 @@ print e def do_tselect(self, arg): - '''executes a query and prints the result in trasposed form. Useful when querying tables with many columns''' - - self.do_select(arg, terminator='\\t') + '''executes a query and prints the result in trasposed form. Useful when querying tables with many columns''' + self.do_select(self.parsed(arg, terminator='\\t')) def do_sql(self,args): '''prints sql statement give the sql_id (Oracle 10gR2)''' @@ -153,8 +152,17 @@ print e def do_sessinfo(self,args): - '''Reports session info for the give sid, extended to RAC with gv$''' - self.do_tselect('* from gv$session where sid='+args+';') + '''Reports session info for the given sid, extended to RAC with gv$''' + try: + if not args: + self.curs.execute('SELECT sid FROM v$mystat') + args = self.curs.fetchone()[0] + self.onecmd('SELECT * from gv$session where sid=%s\\t' % args) + except cx_Oracle.DatabaseError, e: + if 'table or view does not exist' in str(e): + print 'This account has not been granted SELECT privileges to v$mystat or gv$session.' + else: + raise def do_sleect(self,args): '''implements sleect = select, a common typo''' diff -r 1c3df79fd088 -r ed46f2dba929 sqlpython/sqlpyPlus.py --- a/sqlpython/sqlpyPlus.py Fri Dec 12 10:14:09 2008 -0500 +++ b/sqlpython/sqlpyPlus.py Thu Dec 18 10:10:27 2008 -0500 @@ -23,7 +23,7 @@ - catherinedevlin.blogspot.com May 31, 2006 """ -import sys, os, re, sqlpython, cx_Oracle, pyparsing, re, completion, datetime, pickle +import sys, os, re, sqlpython, cx_Oracle, pyparsing, re, completion, datetime, pickle, binascii from cmd2 import Cmd, make_option, options, Statekeeper, Cmd2TestCase from output_templates import output_templates from plothandler import Plot @@ -497,6 +497,10 @@ rowlimitPattern = pyparsing.Word(pyparsing.nums)('rowlimit') terminators = '; \\C \\t \\i \\p \\l \\L \\b '.split() + output_templates.keys() + def expandSelect(self, arg): + #w + Optional(CaselessKeyword('AS')) + Optional(w ^ dblQuotedString) + (CaselessKeyword('FROM') ^ ',') + return arg + def do_select(self, arg, bindVarsIn=None, terminator=None): """Fetch rows from a table. @@ -512,8 +516,9 @@ rowlimit = int(arg.parsed.suffix or 0) except ValueError: rowlimit = 0 - print "Couldn't understand command suffix '%s'" % arg.parsed.suffix + print "Specify desired number of rows after terminator (not '%s')" % arg.parsed.suffix self.varsUsed = findBinds(arg, self.binds, bindVarsIn) + arg = self.expandSelect(arg) self.curs.execute('select ' + arg, self.varsUsed) self.rows = self.curs.fetchmany(min(self.maxfetch, (rowlimit or self.maxfetch))) self.rc = self.curs.rowcount @@ -869,9 +874,6 @@ def do_declare(self, arg): self.anon_plsql('declare ' + arg) - #def do_create(self, arg): - # self.anon_plsql('create ' + arg) - @options([make_option('-l', '--long', action='store_true', help='long descriptions'), make_option('-a', '--all', action='store_true', help="all schemas' objects")]) def do_ls(self, arg, opts):