changeset 207:0351e977c245

folded in sessinfo fix
author catherine@dellzilla
date Thu, 18 Dec 2008 10:20:59 -0500
parents c3dc0c6b6d8c (current diff) ed46f2dba929 (diff)
children 545d98ed07f3
files sqlpython/sqlpyPlus.py
diffstat 2 files changed, 21 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/sqlpython/mysqlpy.py	Thu Dec 18 10:14:32 2008 -0500
+++ b/sqlpython/mysqlpy.py	Thu Dec 18 10:20:59 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'''
--- a/sqlpython/sqlpyPlus.py	Thu Dec 18 10:14:32 2008 -0500
+++ b/sqlpython/sqlpyPlus.py	Thu Dec 18 10:20:59 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):