changeset 264:a8deaa38f11e

show errors works. limiting ls
author catherine@Elli.myhome.westell.com
date Mon, 16 Mar 2009 22:03:41 -0400
parents 362db47c17b4
children 041c656dc8e5
files sqlpython/sqlpyPlus.py sqlpython/sqlpython.py
diffstat 2 files changed, 52 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/sqlpython/sqlpyPlus.py	Mon Mar 16 17:48:54 2009 -0400
+++ b/sqlpython/sqlpyPlus.py	Mon Mar 16 22:03:41 2009 -0400
@@ -721,6 +721,8 @@
         show                  - display value of all sqlpython parameters
         show (parameter name) - display value of a sqlpython parameter
         show parameter (parameter name) - display value of an ORACLE parameter
+        show err              - errors from the most recent PL/SQL object compilation.
+        show all err          - all compilation errors from the user's PL/SQL objects.
         '''
         if arg.startswith('param'):
             try:
@@ -736,7 +738,16 @@
                                      WHEN 6 THEN 'BIG INTEGER' END type, 
                            value FROM v$parameter WHERE name LIKE '%%%s%%';""" % paramname)
         else:
+            argpieces = arg.lower().split()
+            try:
+                if argpieces[0][:3] == 'err':
+                    return self._show_errors(all_users=False, limit=1)
+                elif (argpieces[0], argpieces[1][:3]) == ('all','err'):
+                    return self._show_errors(all_users=False, limit=None)
+            except IndexError:
+                pass
             return Cmd.do_show(self, arg)
+    do_sho = do_show
             
     @options([make_option('-d', '--dump', action='store_true', help='dump results to files'),
               make_option('-f', '--full', action='store_true', help='get dependent objects as well'),
@@ -1151,7 +1162,7 @@
                              OR object_type || '/' || object_name = '%s'""" % \
                             (target, target)
             else:
-                where = "\nWHERE object_type || '/' || object_name LIKE '%%%s%%'" % (arg.upper().replace('*','%'))
+                where = "\nWHERE object_type || '/' || object_name LIKE '%s'" % (arg.upper().replace('*','%'))
         else:
             where = ''
         if opts.all:
--- a/sqlpython/sqlpython.py	Mon Mar 16 17:48:54 2009 -0400
+++ b/sqlpython/sqlpython.py	Mon Mar 16 22:03:41 2009 -0400
@@ -165,7 +165,43 @@
     
     def emptyline(self):
         pass
-                           
+
+    def _show_errors(self, all_users=False, limit=None, mintime=None):
+        if all_users:
+            user = ''
+        else:
+            user = "WHERE ao.owner = user\n"
+        self.curs.execute('''
+            SELECT ae.owner, ae.name, ae.type, ae.position, ae.line, ae.attribute, 
+                   ae.text error_text,
+                   src.text object_text,
+                   ao.last_ddl_time
+            FROM   all_errors ae
+            JOIN   all_objects ao ON (    ae.owner = ao.owner
+                                      AND ae.name = ao.object_name
+                                      AND ae.type = ao.object_type)
+            JOIN   all_source src ON (    ae.owner = src.owner
+                                      AND ae.name = src.name
+                                      AND ae.type = src.type
+                                      AND ae.line = src.line)
+            %sORDER BY ao.last_ddl_time DESC''' % user)
+        if limit is None:
+            errors = self.curs.fetchall()
+        else:
+            errors = self.curs.fetchmany(numRows = limit)
+        for err in errors:
+            if (mintime is not None) and (err[8] < mintime):
+                break
+            print '%s at line %d of %s %s.%s:' % (err[5], err[4], err[2], err[0], err[1])
+            print err[7]
+            print (' ' * (err[3]-1)) + '^'
+            print err[6]
+            print '\n'
+            
+    def current_database_time(self):
+        self.curs.execute('select sysdate from dual')
+        return self.curs.fetchone()[0]
+        
     def do_terminators(self, arg):
         """;    standard Oracle format
 \\c   CSV (with headings)
@@ -192,33 +228,10 @@
         if 'end' in ending_args:
             command = '%s %s;'
         else:
-            command = '%s %s'        
-        self.curs.execute('select sysdate from dual')
-        timestamp = self.curs.fetchone()[0]
-        self.orcl.commit()
+            command = '%s %s'    
+        current_time = self.current_database_time()
         self.curs.execute(command % (arg.parsed.command, arg.parsed.args), self.varsUsed)
-        self.curs.execute('''
-            SELECT ae.owner, ae.name, ae.type, ae.position, ae.line, ae.attribute, 
-                   ae.text error_text,
-                   src.text object_text,
-                   ao.last_ddl_time
-            FROM   all_errors ae
-            JOIN   all_objects ao ON (    ae.owner = ao.owner
-                                      AND ae.name = ao.object_name
-                                      AND ae.type = ao.object_type)
-            JOIN   all_source src ON (    ae.owner = src.owner
-                                      AND ae.name = src.name
-                                      AND ae.type = src.type
-                                      AND ae.line = src.line)
-            WHERE  ao.last_ddl_time >= :timestamp
-            ORDER BY ae.sequence ASC'''
-                          , {'timestamp': timestamp}
-                                       )
-        for err in self.curs:
-            print '%s at line %d of %s %s.%s:' % (err[5], err[4], err[2], err[0], err[1])
-            print err[7]
-            print (' ' * (err[3]-1)) + '^'
-            print err[6]
+        self._show_errors(all_users=True, limit=1, mintime=current_time)
         print '\nExecuted%s\n' % ((self.curs.rowcount > 0) and ' (%d rows)' % self.curs.rowcount or '')
             
     def do_commit(self, arg=''):