# HG changeset patch # User catherine@localhost # Date 1210800232 14400 # Node ID 83de0cb04f12e7d931be88709be540775a0c5c5c # Parent 01d578f4e6e7b9a2c622cf5d53914413df7a6453 prevent crash on lone backslash diff -r 01d578f4e6e7 -r 83de0cb04f12 sqlpyPlus.py --- a/sqlpyPlus.py Mon Apr 28 12:20:53 2008 -0400 +++ b/sqlpyPlus.py Wed May 14 17:23:52 2008 -0400 @@ -12,7 +12,7 @@ - comments shows table and column comments - compare ... to ... graphically compares results of two queries - commands are case-insensitive - + Use 'help' within sqlpython for details. Compatible with sqlpython v1.3 @@ -28,27 +28,27 @@ descQueries = { 'TABLE': (""" - atc.column_name, - CASE atc.nullable WHEN 'Y' THEN 'NULL' ELSE 'NOT NULL' END "Null?", - atc.data_type || - CASE atc.data_type WHEN 'DATE' THEN '' - ELSE '(' || - CASE atc.data_type WHEN 'NUMBER' THEN TO_CHAR(atc.data_precision) || - CASE atc.data_scale WHEN 0 THEN '' - ELSE ',' || TO_CHAR(atc.data_scale) END - ELSE TO_CHAR(atc.data_length) END - END || - CASE atc.data_type WHEN 'DATE' THEN '' ELSE ')' END - data_type + atc.column_name, +CASE atc.nullable WHEN 'Y' THEN 'NULL' ELSE 'NOT NULL' END "Null?", +atc.data_type || +CASE atc.data_type WHEN 'DATE' THEN '' +ELSE '(' || +CASE atc.data_type WHEN 'NUMBER' THEN TO_CHAR(atc.data_precision) || +CASE atc.data_scale WHEN 0 THEN '' +ELSE ',' || TO_CHAR(atc.data_scale) END +ELSE TO_CHAR(atc.data_length) END +END || +CASE atc.data_type WHEN 'DATE' THEN '' ELSE ')' END +data_type FROM all_tab_columns atc WHERE atc.table_name = :object_name AND atc.owner = :owner ORDER BY atc.column_id;""",), 'PROCEDURE': (""" - argument_name, - data_type, - in_out, - default_value + argument_name, +data_type, +in_out, +default_value FROM all_arguments WHERE object_name = :object_name AND owner = :owner @@ -61,11 +61,11 @@ WHERE package_name = :package_name AND owner = :owner""",), 'PackageObjArgs':(""" - object_name, - argument_name, - data_type, - in_out, - default_value + object_name, +argument_name, +data_type, +in_out, +default_value FROM all_arguments WHERE package_name = :package_name AND object_name = :object_name @@ -73,20 +73,20 @@ AND argument_name IS NOT NULL ORDER BY sequence""",), 'TRIGGER':(""" - description + description FROM all_triggers WHERE owner = :owner AND trigger_name = :object_name """, """ - table_owner, - base_object_type, - table_name, - column_name, - when_clause, - status, - action_type, - crossedition +table_owner, +base_object_type, +table_name, +column_name, +when_clause, +status, +action_type, +crossedition FROM all_triggers WHERE owner = :owner AND trigger_name = :object_name @@ -111,37 +111,37 @@ AND index_name = :object_name \\t """,) - } +} descQueries['VIEW'] = descQueries['TABLE'] descQueries['FUNCTION'] = descQueries['PROCEDURE'] queries = { 'resolve': """ SELECT object_type, object_name, owner FROM ( - SELECT object_type, object_name, user owner, 1 priority - FROM user_objects - WHERE object_name = :objName - UNION ALL - SELECT ao.object_type, ao.object_name, ao.owner, 2 priority - FROM all_objects ao - JOIN user_synonyms us ON (us.table_owner = ao.owner AND us.table_name = ao.object_name) - WHERE us.synonym_name = :objName - AND ao.object_type != 'SYNONYM' - UNION ALL - SELECT ao.object_type, ao.object_name, ao.owner, 3 priority - FROM all_objects ao - JOIN all_synonyms asyn ON (asyn.table_owner = ao.owner AND asyn.table_name = ao.object_name) - WHERE asyn.synonym_name = :objName - AND ao.object_type != 'SYNONYM' - AND asyn.owner = 'PUBLIC' - UNION ALL - SELECT 'DIRECTORY' object_type, dir.directory_name, dir.owner, 6 priority - FROM all_directories dir - WHERE dir.directory_name = :objName - UNION ALL - SELECT 'DATABASE LINK' object_type, db_link, owner, 7 priority - FROM all_db_links dbl - WHERE dbl.db_link = :objName +SELECT object_type, object_name, user owner, 1 priority +FROM user_objects +WHERE object_name = :objName +UNION ALL +SELECT ao.object_type, ao.object_name, ao.owner, 2 priority +FROM all_objects ao +JOIN user_synonyms us ON (us.table_owner = ao.owner AND us.table_name = ao.object_name) +WHERE us.synonym_name = :objName +AND ao.object_type != 'SYNONYM' +UNION ALL +SELECT ao.object_type, ao.object_name, ao.owner, 3 priority +FROM all_objects ao +JOIN all_synonyms asyn ON (asyn.table_owner = ao.owner AND asyn.table_name = ao.object_name) +WHERE asyn.synonym_name = :objName +AND ao.object_type != 'SYNONYM' +AND asyn.owner = 'PUBLIC' +UNION ALL +SELECT 'DIRECTORY' object_type, dir.directory_name, dir.owner, 6 priority +FROM all_directories dir +WHERE dir.directory_name = :objName +UNION ALL +SELECT 'DATABASE LINK' object_type, db_link, owner, 7 priority +FROM all_db_links dbl +WHERE dbl.db_link = :objName ) ORDER BY priority ASC""", 'tabComments': """ SELECT comments @@ -150,7 +150,7 @@ AND table_name = :table_name""", 'colComments': """ atc.column_name, - acc.comments +acc.comments FROM all_tab_columns atc JOIN all_col_comments acc ON (atc.owner = acc.owner and atc.table_name = acc.table_name and atc.column_name = acc.column_name) WHERE atc.table_name = :object_name @@ -158,31 +158,31 @@ ORDER BY atc.column_id;""", #thanks to Senora.pm for "refs" 'refs': """ - NULL referenced_by, - c2.table_name references, - c1.constraint_name constraint +NULL referenced_by, +c2.table_name references, +c1.constraint_name constraint FROM - user_constraints c1, - user_constraints c2 +user_constraints c1, +user_constraints c2 WHERE - c1.table_name = :object_name - and c1.constraint_type ='R' - and c1.r_constraint_name = c2.constraint_name - and c1.r_owner = c2.owner - and c1.owner = :owner +c1.table_name = :object_name +and c1.constraint_type ='R' +and c1.r_constraint_name = c2.constraint_name +and c1.r_owner = c2.owner +and c1.owner = :owner UNION SELECT c1.table_name referenced_by, - NULL references, - c1.constraint_name constraint +NULL references, +c1.constraint_name constraint FROM - user_constraints c1, - user_constraints c2 +user_constraints c1, +user_constraints c2 WHERE - c2.table_name = :object_name - and c1.constraint_type ='R' - and c1.r_constraint_name = c2.constraint_name - and c1.r_owner = c2.owner - and c1.owner = :owner +c2.table_name = :object_name +and c1.constraint_type ='R' +and c1.r_constraint_name = c2.constraint_name +and c1.r_owner = c2.owner +and c1.owner = :owner """ } @@ -192,7 +192,7 @@ if float(sys.version[:3]) < 2.3: def enumerate(lst): return zip(range(len(lst)), lst) - + class SoftwareSearcher(object): def __init__(self, softwareList, purpose): self.softwareList = softwareList @@ -212,51 +212,51 @@ if os.path.exists(software): if n > (len(self.softwareList) * 0.7): print """ - - Using %s. Note that there are better options available for %s, - but %s couldn't find a better one in your PATH. - Feel free to open up %s - and customize it to find your favorite %s program. - - """ % (software, self.purpose, __file__, __file__, self.purpose) + + Using %s. Note that there are better options available for %s, + but %s couldn't find a better one in your PATH. + Feel free to open up %s + and customize it to find your favorite %s program. + + """ % (software, self.purpose, __file__, __file__, self.purpose) return (software, invokeString) stem = os.path.split(software)[1] for p in os.environ['PATH'].split(os.pathsep): if os.path.exists(os.sep.join([p, stem])): return (stem, invokeString) raise (OSError, """Could not find any %s programs. You will need to install one, - or customize %s to make it aware of yours. - Looked for these programs: - %s""" % (self.purpose, __file__, "\n".join([s[0] for s in self.softwareList]))) + or customize %s to make it aware of yours. +Looked for these programs: +%s""" % (self.purpose, __file__, "\n".join([s[0] for s in self.softwareList]))) #v2.4: %s""" % (self.purpose, __file__, "\n".join(s[0] for s in self.softwareList))) softwareLists = { 'diff/merge': [ - ('/usr/bin/meld',"%s %s %s"), - ('/usr/bin/kdiff3',"%s %s %s"), - (r'C:\Program Files\Araxis\Araxis Merge v6.5\Merge.exe','"%s" %s %s'), - (r'C:\Program Files\TortoiseSVN\bin\TortoiseMerge.exe', '"%s" /base:"%s" /mine:"%s"'), - ('FileMerge','%s %s %s'), - ('kompare','%s %s %s'), - ('WinMerge','%s %s %s'), - ('xxdiff','%s %s %s'), - ('fldiff','%s %s %s'), - ('gtkdiff','%s %s %s'), - ('tkdiff','%s %s %s'), - ('gvimdiff','%s %s %s'), - ('diff',"%s %s %s"), - (r'c:\windows\system32\comp.exe',"%s %s %s")], - 'text editor': [ - ('gedit', '%s %s'), - ('textpad', '%s %s'), - ('notepad.exe', '%s %s'), - ('pico', '%s %s'), - ('emacs', '%s %s'), - ('vim', '%s %s'), - ('vi', '%s %s'), - ('ed', '%s %s'), - ('edlin', '%s %s') - ] + ('/usr/bin/meld',"%s %s %s"), + ('/usr/bin/kdiff3',"%s %s %s"), + (r'C:\Program Files\Araxis\Araxis Merge v6.5\Merge.exe','"%s" %s %s'), + (r'C:\Program Files\TortoiseSVN\bin\TortoiseMerge.exe', '"%s" /base:"%s" /mine:"%s"'), + ('FileMerge','%s %s %s'), + ('kompare','%s %s %s'), + ('WinMerge','%s %s %s'), + ('xxdiff','%s %s %s'), + ('fldiff','%s %s %s'), + ('gtkdiff','%s %s %s'), + ('tkdiff','%s %s %s'), + ('gvimdiff','%s %s %s'), + ('diff',"%s %s %s"), + (r'c:\windows\system32\comp.exe',"%s %s %s")], + 'text editor': [ + ('gedit', '%s %s'), + ('textpad', '%s %s'), + ('notepad.exe', '%s %s'), + ('pico', '%s %s'), + ('emacs', '%s %s'), + ('vim', '%s %s'), + ('vi', '%s %s'), + ('ed', '%s %s'), + ('edlin', '%s %s') + ] } diffMergeSearcher = SoftwareSearcher(softwareLists['diff/merge'],'diff/merge') @@ -338,12 +338,12 @@ if not givenBindVars.has_key(varname): print 'Bind variable %s not defined.' % (varname) return result - + class sqlpyPlus(sqlpython.sqlpython): defaultExtension = 'sql' shortcuts = {'?': 'help', '@': 'getrun', '!': 'shell', ':': 'setbind', '\\': 'psql'} multilineCommands = '''select insert update delete tselect - create drop alter'''.split() + create drop alter'''.split() defaultFileName = 'afiedt.buf' def __init__(self): sqlpython.sqlpython.__init__(self) @@ -364,15 +364,15 @@ the arguments. Returns a tuple containing (command, args, line). 'command' and 'args' may be None if the line couldn't be parsed. Overrides cmd.cmd.parseline to accept variety of shortcuts..""" - + cmd, arg, line = sqlpython.sqlpython.parseline(self, line) if cmd in ('select', 'sleect', 'insert', 'update', 'delete', 'describe', - 'desc', 'comments', 'pull', 'refs', 'desc', 'triggers', 'find') \ - and not hasattr(self, 'curs'): + 'desc', 'comments', 'pull', 'refs', 'desc', 'triggers', 'find') \ + and not hasattr(self, 'curs'): print 'Not connected.' return '', '', '' return cmd, arg, line - + def onecmd_plus_hooks(self, line): line = self.precmd(line) stop = self.onecmd(line) @@ -402,7 +402,7 @@ (self.tblname, ','.join(self.colnames), formatRow(row)) for row in self.rows] return '\n'.join(result) - + def output_row_as_xml(self, row): result = [' <%s>\n %s\n %s>' % (colname.lower(), str('' if (itm is None) else itm), colname.lower()) @@ -421,7 +421,7 @@ result.append('