Mercurial > sqlpython
comparison sqlpyPlus.py @ 83:5701fb63e81d
trying --all option for dt, di, etc.
author | catherine@cordelia |
---|---|
date | Thu, 15 May 2008 17:28:12 -0400 |
parents | 5485b66c3445 |
children | a7be838c4ad5 |
comparison
equal
deleted
inserted
replaced
82:5485b66c3445 | 83:5701fb63e81d |
---|---|
556 arg = arg.lower() | 556 arg = arg.lower() |
557 else: | 557 else: |
558 searchfor = "text" | 558 searchfor = "text" |
559 self.do_select("* from all_source where %s like '%%%s%%'" % (searchfor, arg)) | 559 self.do_select("* from all_source where %s like '%%%s%%'" % (searchfor, arg)) |
560 | 560 |
561 def do_describe(self, arg): | 561 @options([make_option('-a','--all',action='store_true', |
562 help='Describe all objects (not just my own)')]) | |
563 def do_describe(self, arg, opts): | |
562 "emulates SQL*Plus's DESCRIBE" | 564 "emulates SQL*Plus's DESCRIBE" |
565 | |
566 if opts.all: | |
567 which_view = (', owner', 'all') | |
568 else: | |
569 which_view = ('', 'user') | |
563 | 570 |
564 if not arg: | 571 if not arg: |
565 self.do_select("""object_name, object_type, owner FROM all_objects WHERE object_type IN ('TABLE','VIEW','INDEX') ORDER BY object_name""") | 572 self.do_select("""object_name, object_type%s FROM %s_objects WHERE object_type IN ('TABLE','VIEW','INDEX') ORDER BY object_name""" % which_view) |
566 return | 573 return |
567 object_type, owner, object_name = self.resolve(arg.strip(self.terminator).upper()) | 574 object_type, owner, object_name = self.resolve(arg.strip(self.terminator).upper()) |
568 if not object_type: | 575 if not object_type: |
569 self.do_select("""object_name, object_type, owner FROM all_objects | 576 if opts.all: |
570 WHERE object_type IN ('TABLE','VIEW','INDEX') | 577 self.do_select("""object_name, object_type%s FROM %s_objects |
571 AND object_name LIKE '%%%s%%' | 578 WHERE object_type IN ('TABLE','VIEW','INDEX') |
572 ORDER BY object_name""" % arg.upper() ) | 579 AND object_name LIKE '%%%s%%' |
580 ORDER BY object_name""" % | |
581 (which_view[0], which_view[1], arg.upper()) ) | |
573 return | 582 return |
574 self.stdout.write("%s %s.%s\n" % (object_type, owner, object_name)) | 583 self.stdout.write("%s %s.%s\n" % (object_type, owner, object_name)) |
575 descQ = descQueries.get(object_type) | 584 descQ = descQueries.get(object_type) |
576 if descQ: | 585 if descQ: |
577 for q in descQ: | 586 for q in descQ: |
727 try: | 736 try: |
728 return self.onecmd('%s %s' % (commands[abbrev], args)) | 737 return self.onecmd('%s %s' % (commands[abbrev], args)) |
729 except KeyError: | 738 except KeyError: |
730 print 'psql command \%s not yet supported.' % abbrev | 739 print 'psql command \%s not yet supported.' % abbrev |
731 | 740 |
741 @options([make_option('-a','--all',action='store_true', | |
742 help='Describe all objects (not just my own)')]) | |
732 def do__dir_tables(self, arg): | 743 def do__dir_tables(self, arg): |
733 self.do_select("""table_name, 'TABLE' as type, owner FROM all_tables WHERE table_name LIKE '%%%s%%'""" % arg.upper()) | 744 if opts.all: |
734 | 745 which_view = (', owner', 'all') |
746 else: | |
747 which_view = ('', 'user') | |
748 self.do_select("""table_name, 'TABLE' as type%s FROM %s_tables WHERE table_name LIKE '%%%s%%'""" % | |
749 (which_view[0], which_view[1], arg.upper())) | |
750 | |
751 @options([make_option('-a','--all',action='store_true', | |
752 help='Describe all objects (not just my own)')]) | |
735 def do__dir_views(self, arg): | 753 def do__dir_views(self, arg): |
736 self.do_select("""view_name, 'VIEW' as type, owner FROM all_views WHERE view_name LIKE '%%%s%%'""" % arg.upper()) | 754 if opts.all: |
737 | 755 which_view = (', owner', 'all') |
756 else: | |
757 which_view = ('', 'user') | |
758 self.do_select("""view_name, 'VIEW' as type%s FROM %s_views WHERE view_name LIKE '%%%s%%'""" % | |
759 (which_view[0], which_view[1], arg.upper())) | |
760 | |
761 @options([make_option('-a','--all',action='store_true', | |
762 help='Describe all objects (not just my own)')]) | |
738 def do__dir_indexes(self, arg): | 763 def do__dir_indexes(self, arg): |
739 self.do_select("""index_name, index_type, owner FROM all_indexes WHERE index_name LIKE '%%%s%%' OR table_name LIKE '%%%s%%'""" % (arg.upper(), arg.upper())) | 764 if opts.all: |
765 which_view = (', owner', 'all') | |
766 else: | |
767 which_view = ('', 'user') | |
768 self.do_select("""index_name, index_type%s FROM %s_indexes WHERE index_name LIKE '%%%s%%' OR table_name LIKE '%%%s%%'""" % | |
769 (which_view[0], which_view[1], arg.upper(), arg.upper())) | |
740 | 770 |
741 def do__dir_tablespaces(self, arg): | 771 def do__dir_tablespaces(self, arg): |
742 self.do_select("""tablespace_name, file_name from dba_data_files""") | 772 self.do_select("""tablespace_name, file_name from dba_data_files""") |
743 | 773 |
744 def do__dir_schemas(self, arg): | 774 def do__dir_schemas(self, arg): |