comparison sqlpyPlus.py @ 77:4b5d4e5798dd

\d with wildcard
author catherine@cordelia
date Tue, 22 Apr 2008 09:32:55 -0400
parents 9427aa0726fa
children 8529876f7541
comparison
equal deleted inserted replaced
76:9427aa0726fa 77:4b5d4e5798dd
562 searchfor = "text" 562 searchfor = "text"
563 self.do_select("* from all_source where %s like '%%%s%%'" % (searchfor, arg)) 563 self.do_select("* from all_source where %s like '%%%s%%'" % (searchfor, arg))
564 564
565 def do_describe(self, arg): 565 def do_describe(self, arg):
566 "emulates SQL*Plus's DESCRIBE" 566 "emulates SQL*Plus's DESCRIBE"
567
568 if not arg:
569 self.do_select("""object_name, object_type FROM all_objects WHERE object_type IN ('TABLE','VIEW','INDEX') ORDER BY object_name""")
570 return
567 object_type, owner, object_name = self.resolve(arg.strip(self.terminator).upper()) 571 object_type, owner, object_name = self.resolve(arg.strip(self.terminator).upper())
572 if not object_type:
573 self.do_select("""object_name, object_type FROM all_objects
574 WHERE object_type IN ('TABLE','VIEW','INDEX')
575 AND object_name LIKE '%%%s%%'
576 ORDER BY object_name""" % arg.upper() )
577 return
568 self.stdout.write("%s %s.%s\n" % (object_type, owner, object_name)) 578 self.stdout.write("%s %s.%s\n" % (object_type, owner, object_name))
569 descQ = descQueries.get(object_type) 579 descQ = descQueries.get(object_type)
570 if descQ: 580 if descQ:
571 for q in descQ: 581 for q in descQ:
572 self.do_select(q,bindVarsIn={'object_name':object_name, 'owner':owner}) 582 self.do_select(q,bindVarsIn={'object_name':object_name, 'owner':owner})
677 \g run 687 \g run
678 \h help 688 \h help
679 \i getrun 689 \i getrun
680 \o spool 690 \o spool
681 \p list 691 \p list
692 \q quit
682 \w save 693 \w save
683 \db _dir_tablespaces 694 \db _dir_tablespaces
684 \dd comments 695 \dd comments
685 \dn _dir_schemas 696 \dn _dir_schemas
686 \dt _dir_tables 697 \dt _dir_tables
696 try: 707 try:
697 args = words[1] 708 args = words[1]
698 except IndexError: 709 except IndexError:
699 args = '' 710 args = ''
700 try: 711 try:
701 self.onecmd('%s %s' % (commands[abbrev], args)) 712 return self.onecmd('%s %s' % (commands[abbrev], args))
702 self.onecmd('q')
703 except KeyError: 713 except KeyError:
704 print 'psql command \%s not yet supported.' % abbrev 714 print 'psql command \%s not yet supported.' % abbrev
705 715
706 def do__dir_tables(self, arg): 716 def do__dir_tables(self, arg):
707 self.do_select("""table_name, 'TABLE' as type, owner FROM all_tables WHERE table_name LIKE '%%%s%%'""" % arg.upper()) 717 self.do_select("""table_name, 'TABLE' as type, owner FROM all_tables WHERE table_name LIKE '%%%s%%'""" % arg.upper())
708 718
709 def do__dir_views(self, arg): 719 def do__dir_views(self, arg):
710 self.do_select("""view_name, 'VIEW' as type, owner FROM all_views WHERE view_name LIKE '%%%s%%'""" % arg.upper()) 720 self.do_select("""view_name, 'VIEW' as type, owner FROM all_views WHERE view_name LIKE '%%%s%%'""" % arg.upper())
711 721
712 def do__dir_indexes(self, arg): 722 def do__dir_indexes(self, arg):
713 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())) 723 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()))