changeset 180:9e6c1ec07ebc

ls simplified & has col labels
author catherine@Elli.myhome.westell.com
date Wed, 05 Nov 2008 17:01:01 -0500
parents 7e3921829399
children b5114b8828b1
files sqlpython/exampleSession.txt sqlpython/sqlpyPlus.py sqlpython/sqlpython.py
diffstat 3 files changed, 25 insertions(+), 74 deletions(-) [+]
line wrap: on
line diff
--- a/sqlpython/exampleSession.txt	Wed Nov 05 07:41:42 2008 -0500
+++ b/sqlpython/exampleSession.txt	Wed Nov 05 17:01:01 2008 -0500
@@ -191,7 +191,6 @@
 maxtselctrows: 10
 maxfetch: 1000
 autobind: False
-failover: False
 timeout: 30
 commit_on_exit: True
 testschema@eqtest> set autobind on
@@ -232,4 +231,7 @@
 The Tempest Shakespeare
 Agamemnon   Aeschylus
 
-2 rows selected.
\ No newline at end of file
+2 rows selected.
+testschema@eqtest> ls play
+INDEX/XPK_PLAY
+TABLE/PLAY
--- a/sqlpython/sqlpyPlus.py	Wed Nov 05 07:41:42 2008 -0500
+++ b/sqlpython/sqlpyPlus.py	Wed Nov 05 17:01:01 2008 -0500
@@ -365,13 +365,12 @@
         self.binds = CaselessDict()
         self.sqlBuffer = []
         self.settable = ['maxtselctrows', 'maxfetch', 'autobind', 
-                         'failover', 'timeout', 'commit_on_exit'] # settables must be lowercase
+                         'timeout', 'commit_on_exit'] # settables must be lowercase
         self.stdoutBeforeSpool = sys.stdout
         self.spoolFile = None
         self.autobind = False
-        self.failover = False
-    def default(self, arg, do_everywhere=False):
-        sqlpython.sqlpython.default(self, arg, do_everywhere)
+    def default(self, arg):
+        sqlpython.sqlpython.default(self, arg)
         self.sqlBuffer.append(self.query)            
 
     # overrides cmd's parseline
@@ -929,28 +928,20 @@
         else:
             where = ''
         if opts.all:
-            owner = 'owner'
             whose = 'all'
+            objname = "owner || '.' || object_name"            
         else:
-            owner = "'' AS owner"
             whose = 'user'
-        result = []
-        statement = '''SELECT object_type, object_name,
-                  status, last_ddl_time, %s
+            objname = 'object_name'            
+        if opts.long:
+            extraInfo = ', status, last_ddl_time AS modified'
+        else:
+            extraInfo = ''
+        statement = '''SELECT object_type || '/' || %s AS name %s 
                   FROM   %s_objects %s
-                  ORDER BY object_type, object_name''' % (owner, whose, where)
-        self.curs.execute(statement)
-        for (object_type, object_name, status, last_ddl_time, owner) in self.curs.fetchall():
-            if opts.all:
-                qualified_name = '%s.%s' % (owner, object_name)
-            else:
-                qualified_name = object_name
-            if opts.long:
-                result.append('%s\t%s\t%s/%s' % (status, last_ddl_time, object_type, qualified_name))
-            else:
-                result.append('%s/%s' % (object_type, qualified_name))
-        self.stdout.write('\n'.join(result) + '\n')
-
+                  ORDER BY object_type, object_name;''' % (objname, extraInfo, whose, where)
+        self.onecmd(statement)
+        
     def do_cat(self, arg):
         '''cat TABLENAME --> SELECT * FROM equivalent'''
         if not arg:
--- a/sqlpython/sqlpython.py	Wed Nov 05 07:41:42 2008 -0500
+++ b/sqlpython/sqlpython.py	Wed Nov 05 17:01:01 2008 -0500
@@ -9,7 +9,7 @@
 # See also http://twiki.cern.ch/twiki/bin/view/PSSGroup/SqlPython
 
 import cmd2,getpass,binascii,cx_Oracle,re,os
-import pexpecter, sqlpyPlus
+import sqlpyPlus
 __version__ = '1.5.0'    
     # complication! separate sessions ->
     # separate transactions !!!!!
@@ -22,7 +22,6 @@
         cmd2.Cmd.__init__(self)
         self.prompt = 'SQL.No_Connection> '
         self.maxfetch = 1000
-        self.failoverSessions = []
         self.terminator = ';'
         self.timeout = 30
         self.commit_on_exit = True
@@ -67,34 +66,13 @@
             self.orcl = cx_Oracle.connect(orauser,orapass,oraserv,modeval)
             self.curs = self.orcl.cursor()
             self.prompt = '%s@%s> ' % (orauser, sid)
-            self.failoverSessions = [f for f in [fbs(arg) for fbs in pexpecter.available] if f.available]
         except Exception, e:
             print e
             
     
     def emptyline(self):
         pass
-    
-    def fail(self, arg, do_everywhere=False):
-        if self.failover:
-            success, result = False, ''
-            for fbs in self.failoverSessions:
-                success, result = fbs.attempt(arg)
-                if success:
-                    print result
-                    if not do_everywhere:
-                        return True
-            print result 
-        return False
-                
-    def designated_session(self, arg, sesstype):
-        for fbs in self.failoverSessions:
-            if fbs.valid and fbs.__class__ == sesstype:
-                success, result = fbs.attempt(arg)
-                print result
-                return
-        print 'Valid %s not found' % (sesstype.__name__)
-        
+                           
     def do_terminators(self, arg):
         """;    standard Oracle format
 \\c   CSV (with headings)
@@ -115,37 +93,17 @@
     
     terminatorSearchString = '|'.join('\\' + d.split()[0] for d in do_terminators.__doc__.splitlines())
         
-    def do_yasql(self, arg):
-        '''Sends a command to a YASQL session (http://sourceforge.net/projects/yasql/)'''
-        self.designated_session(arg, pexpecter.YASQLSession)
-    do_y = do_yasql
-    def do_sqlplus(self, arg):
-        '''Sends a command to a SQL*Plus session'''
-        self.designated_session(arg, pexpecter.SqlPlusSession)
-    do_sqlp = do_sqlplus
-    def do_senora(self, arg):
-        '''Sends a command to a Senora session (http://senora.sourceforge.net/)'''
-        self.designated_session(arg, pexpecter.SenoraSession)
-    do_sen = do_senora       
-
-    def default(self, arg, do_everywhere = False):
+    def default(self, arg):
         statement = self.parsed(arg)
         self.query = statement.unterminated
-        try:
-            self.varsUsed = sqlpyPlus.findBinds(self.query, self.binds, givenBindVars={})
-            self.curs.execute(self.query, self.varsUsed)            
-            print '\nExecuted%s\n' % ((self.curs.rowcount > 0) and ' (%d rows)' % self.curs.rowcount or '')
-            if do_everywhere:
-                self.fail(arg, do_everywhere = True )
-        except Exception, e:
-            result = self.fail(arg)
-            if not result:
-                print str(e)
+        self.varsUsed = sqlpyPlus.findBinds(self.query, self.binds, givenBindVars={})
+        self.curs.execute(self.query, self.varsUsed)            
+        print '\nExecuted%s\n' % ((self.curs.rowcount > 0) and ' (%d rows)' % self.curs.rowcount or '')
             
     def do_commit(self, arg):
-        self.default('commit %s;' % (arg), do_everywhere=True)
+        self.default('commit %s;' % (arg))
     def do_rollback(self, arg):
-        self.default('rollback %s;' % (arg), do_everywhere=True)        
+        self.default('rollback %s;' % (arg))        
     def do_quit(self, arg):
         if self.commit_on_exit and hasattr(self, 'curs'):
             self.default('commit;')