comparison sqlpyPlus.py @ 129:d8661065fb77

added -c option to find
author catherine@localhost
date Fri, 15 Aug 2008 09:45:48 -0400
parents c5e6e475cdbe
children 40bbe808e98a
comparison
equal deleted inserted replaced
128:c5e6e475cdbe 129:d8661065fb77
569 self.stdout.write(str(self.curs.callfunc('DBMS_METADATA.GET_DEPENDENT_DDL', cx_Oracle.CLOB, 569 self.stdout.write(str(self.curs.callfunc('DBMS_METADATA.GET_DEPENDENT_DDL', cx_Oracle.CLOB,
570 [dependent_type, object_name, owner]))) 570 [dependent_type, object_name, owner])))
571 except cx_Oracle.DatabaseError: 571 except cx_Oracle.DatabaseError:
572 pass 572 pass
573 573
574 @options([make_option('-i', '--insensitive', action='store_true', help='case-insensitive search'), 574 @options([make_option('-a','--all',action='store_true', help='Find in all schemas (not just my own)'),
575 make_option('-i', '--insensitive', action='store_true', help='case-insensitive search'),
575 make_option('-c', '--col', action='store_true', help='find column'), 576 make_option('-c', '--col', action='store_true', help='find column'),
576 make_option('-t', '--table', action='store_true', help='find table')]) 577 make_option('-t', '--table', action='store_true', help='find table')])
577 def do_find(self, arg, opts): 578 def do_find(self, arg, opts):
578 """Finds argument in source code or (with -c) in column definitions.""" 579 """Finds argument in source code or (with -c) in column definitions."""
579 580
580 arg = self.parsed(arg).unterminated.upper() 581 arg = self.parsed(arg).unterminated.upper()
582
581 if opts.col: 583 if opts.col:
582 self.do_select("owner, table_name, column_name from all_tab_columns where column_name like '%%%s%%'" % (arg)) 584 sql = "owner, table_name, column_name from all_tab_columns where column_name like '%%%s%%'" % (arg)
583 elif opts.table: 585 elif opts.table:
584 self.do_select("owner, table_name from all_tables where table_name like '%%%s%%'" % (arg)) 586 sql = "owner, table_name from all_tables where table_name like '%%%s%%'" % (arg)
585 else: 587 else:
586 if opts.insensitive: 588 if opts.insensitive:
587 searchfor = "LOWER(text)" 589 searchfor = "LOWER(text)"
588 arg = arg.lower() 590 arg = arg.lower()
589 else: 591 else:
590 searchfor = "text" 592 searchfor = "text"
591 self.do_select("* from all_source where %s like '%%%s%%'" % (searchfor, arg)) 593 sql = "* from all_source where %s like '%%%s%%'" % (searchfor, arg)
594 if not opts.all:
595 sql = '%s and owner = user' % (sql)
596 self.do_select(sql)
592 597
593 @options([make_option('-a','--all',action='store_true', 598 @options([make_option('-a','--all',action='store_true',
594 help='Describe all objects (not just my own)')]) 599 help='Describe all objects (not just my own)')])
595 def do_describe(self, arg, opts): 600 def do_describe(self, arg, opts):
596 "emulates SQL*Plus's DESCRIBE" 601 "emulates SQL*Plus's DESCRIBE"