# HG changeset patch # User catherine@Elli.myhome.westell.com # Date 1237255421 14400 # Node ID a8deaa38f11ece96dda9c36f368feabad42a7bc5 # Parent 362db47c17b41a909dee4f8b8d03700e8edb25d8 show errors works. limiting ls diff -r 362db47c17b4 -r a8deaa38f11e sqlpython/sqlpyPlus.py --- 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: diff -r 362db47c17b4 -r a8deaa38f11e sqlpython/sqlpython.py --- 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=''):