comparison sqlpyPlus.py @ 133:25cbb45b190d

column completion working
author catherine@Elli.myhome.westell.com
date Wed, 27 Aug 2008 22:21:44 -0400
parents 2baecb3d5356
children b532bc8430a6
comparison
equal deleted inserted replaced
132:2baecb3d5356 133:25cbb45b190d
524 stmt = "SELECT column_name FROM user_tab_columns WHERE column_name LIKE '%s%%'" 524 stmt = "SELECT column_name FROM user_tab_columns WHERE column_name LIKE '%s%%'"
525 completions = self.select_list(stmt % (text)) 525 completions = self.select_list(stmt % (text))
526 if not completions: 526 if not completions:
527 stmt = "SELECT column_name FROM all_tab_columns WHERE column_name LIKE '%s%%'" 527 stmt = "SELECT column_name FROM all_tab_columns WHERE column_name LIKE '%s%%'"
528 completions = self.select_list(stmt % (text)) 528 completions = self.select_list(stmt % (text))
529 elif segment in ('from', 'update'): 529 if segment == 'from':
530 columnNames = self.columnNameRegex.search(line)
531 if columnNames:
532 columnNames = columnNames.group(1)
533 columnNames = [c.strip().upper() for c in columnNames.split(',')]
534 stmt1 = "SELECT table_name FROM all_tab_columns WHERE column_name = '%s' AND table_name LIKE '%s%%'"
535 for columnName in columnNames:
536 completions.extend(self.select_list(stmt1 % (columnName, text)))
537 if segment in ('from', 'update') and (not completions):
530 stmt = "SELECT table_name FROM user_tables WHERE table_name LIKE '%s%%'" 538 stmt = "SELECT table_name FROM user_tables WHERE table_name LIKE '%s%%'"
531 completions = self.select_list(stmt % (text)) 539 completions = self.select_list(stmt % (text))
532 if not completions: 540 if not completions:
533 stmt = """SELECT table_name FROM user_tables WHERE table_name LIKE '%s%%' 541 stmt = """SELECT table_name FROM user_tables WHERE table_name LIKE '%s%%'
534 UNION 542 UNION
535 SELECT DISTINCT owner FROM all_tables WHERE owner LIKE '%%%s'""" 543 SELECT DISTINCT owner FROM all_tables WHERE owner LIKE '%%%s'"""
536 completions = self.select_list(stmt % (text, text)) 544 completions = self.select_list(stmt % (text, text))
537 elif segment in ('where', 'group by', 'order by'): 545 if segment in ('where', 'group by', 'order by'):
538 try: 546 try:
539 owner, tableName = self.tableNameRegex.search(line).groups()[2:4] 547 owner, tableName = self.tableNameRegex.search(line).groups()[2:4]
540 except AttributeError: 548 except AttributeError:
541 return [] 549 return []
542 if owner: 550 if owner:
543 stmt = "SELECT column_name FROM all_tab_columns WHERE owner = '%s' AND table_name = '%s'" \ 551 stmt = "SELECT column_name FROM all_tab_columns WHERE owner = '%s' AND table_name = '%s'" \
544 % (owner.upper(), tableName.upper()) 552 % (owner.upper(), tableName.upper())
545 else: 553 else:
546 stmt = "SELECT column_name FROM all_tab_columns WHERE table_name = '%s'" \ 554 stmt = "SELECT column_name FROM all_tab_columns WHERE table_name = '%s'" \
547 % (tableName.upper()) 555 % (tableName.upper())
556 stmt = "%s AND column_name LIKE '%s%%'" % (stmt, text)
548 completions = self.select_list(stmt) 557 completions = self.select_list(stmt)
549 558
550 return completions 559 return completions
551 560
552 rowlimitPattern = pyparsing.Word(pyparsing.nums)('rowlimit') 561 rowlimitPattern = pyparsing.Word(pyparsing.nums)('rowlimit')