diff sqlpyPlus.py @ 77:4b5d4e5798dd

\d with wildcard
author catherine@cordelia
date Tue, 22 Apr 2008 09:32:55 -0400
parents 9427aa0726fa
children 8529876f7541
line wrap: on
line diff
--- a/sqlpyPlus.py	Mon Apr 21 09:35:31 2008 -0400
+++ b/sqlpyPlus.py	Tue Apr 22 09:32:55 2008 -0400
@@ -564,7 +564,17 @@
         
     def do_describe(self, arg):
         "emulates SQL*Plus's DESCRIBE"
+        
+        if not arg:
+            self.do_select("""object_name, object_type FROM all_objects WHERE object_type IN ('TABLE','VIEW','INDEX') ORDER BY object_name""")
+            return
         object_type, owner, object_name = self.resolve(arg.strip(self.terminator).upper())
+        if not object_type:
+            self.do_select("""object_name, object_type FROM all_objects
+                              WHERE object_type IN ('TABLE','VIEW','INDEX')
+                              AND   object_name LIKE '%%%s%%'
+                              ORDER BY object_name""" % arg.upper() )
+            return                    
         self.stdout.write("%s %s.%s\n" % (object_type, owner, object_name))
         descQ = descQueries.get(object_type)
         if descQ:
@@ -679,6 +689,7 @@
         \i getrun
         \o spool
         \p list
+        \q quit
         \w save
         \db _dir_tablespaces
         \dd comments
@@ -698,14 +709,13 @@
         except IndexError:
             args = ''
         try:
-            self.onecmd('%s %s' % (commands[abbrev], args))
-            self.onecmd('q')
+            return self.onecmd('%s %s' % (commands[abbrev], args))
         except KeyError:
             print 'psql command \%s not yet supported.' % abbrev
-            
+
     def do__dir_tables(self, arg):
         self.do_select("""table_name, 'TABLE' as type, owner FROM all_tables WHERE table_name LIKE '%%%s%%'""" % arg.upper())        
-
+        
     def do__dir_views(self, arg):
         self.do_select("""view_name, 'VIEW' as type, owner FROM all_views WHERE view_name LIKE '%%%s%%'""" % arg.upper())