changeset 512:eccf817b0fbc

tab completion semi-repaired
author catherine.devlin@gmail.com
date Fri, 24 Sep 2010 22:14:06 -0400
parents 9dbf99653136
children
files sqlpython/connections.py sqlpython/sqlpyPlus.py
diffstat 2 files changed, 9 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/sqlpython/connections.py	Fri Sep 24 20:38:00 2010 -0400
+++ b/sqlpython/connections.py	Fri Sep 24 22:14:06 2010 -0400
@@ -213,8 +213,8 @@
         curs.execute(qry, binds) 
         return curs
     def columns(self, target, opts):
-        target = self.sql_format_wildcards(target)
-        if opts.all:
+        target = self.name_case(self.sql_format_wildcards(target))
+        if hasattr(opts, 'all') and opts.all:
             owner = '%'
         else:
             owner = self.username
@@ -223,12 +223,13 @@
         binds = (('owner', owner), ('colname', target))
         curs = self.connection.cursor()
         curs.execute(qry, self.bindVariables(binds))
-        return curs
+        return curs.fetchall()
     def source(self, target, opts):
         if opts.all:
             owner = '%'
         else:
             owner = self.username
+        target = '%%%s%%' % target
         qry = self.source_qry % (self.comparison_operator(owner), self.bindSyntax('owner'),
                                                                   self.bindSyntax('target'))
         binds = (('owner', owner), ('target', target))
--- a/sqlpython/sqlpyPlus.py	Fri Sep 24 20:38:00 2010 -0400
+++ b/sqlpython/sqlpyPlus.py	Fri Sep 24 22:14:06 2010 -0400
@@ -419,7 +419,7 @@
         self.default_rdbms = 'oracle'
         self.rdbms_supported = Abbreviatable_List('oracle postgres mysql'.split())
         self.version = 'SQLPython %s' % sqlpython.__version__
-        self.pystate = {'r': [], 'binds': self.binds, 'substs': self.substvars}
+        self.pystate = {'r': [], 'binds': self.binds, 'substs': self.substvars, 'sql': self.onecmd_plus_hooks}
         
     # overrides cmd's parseline
     def parseline(self, line):
@@ -588,17 +588,13 @@
         r'select\s+(.*)from',
         re.IGNORECASE | re.DOTALL | re.MULTILINE)        
     def completedefault(self, text, line, begidx, endidx):
-        (username, gerald_schema) = self.metadata()
         segment = completion.whichSegment(line)        
-        text = text.upper()
         if segment in ('select', 'where', 'having', 'set', 'order by', 'group by'):
-            completions = [c for c in schemas[username].column_names if c.startswith(text)] \
-                          or [c for c in schemas.qual_column_names if c.startswith(text)]
-                          # TODO: the latter not working
+            completions = [c[3] for c in self.current_instance.columns(text + '%', None)]
         elif segment in ('from', 'update', 'insert into'):
             # print schemas[username].table_names
             # TODO: from postgres, these table names are jrrt.fishies, etc.
-            completions = [t for t in schemas[username].table_names if t.startswith(text)]
+            completions = [object_name for (owner, object_type, object_name, synonym_name) in self.current_instance.objects(text + '%', None)]
         elif segment == 'beginning':
             completions = [n for n in self.get_names() if n.startswith('do_')] + [
                            'insert', 'update', 'delete', 'drop', 'alter', 'begin', 'declare', 'create']
@@ -1023,10 +1019,10 @@
         """Finds argument in source code or (with -c) in column definitions."""
         if opts.col:
             for (owner, object_type, table_name, column_name) in self.current_instance.columns(arg, opts):
-                self.poutput('%s %s.%s.%s' % (object_type, owner, table_name, column_name))
+                self.poutput('%s.%s' % (self.object_label(object_type, owner, table_name, None), column_name))
         else:
             for (owner, object_type, name, line_number, txt) in self.current_instance.source(arg, opts):
-                self.poutput('%s %s.%s %d: %s' % (object_type, owner, name, line_number, txt))
+                self.poutput('%s %d: %s' % (self.object_label(object_type, owner, name, None), line_number, txt))
            
     def _col_type_descriptor(self, col):
         #if col['type'] in ('integer',):