changeset 406:4b481c4293b8

beginning completions not working
author catherine@cordelia
date Sun, 11 Oct 2009 10:03:18 -0400
parents 1e3179b31a1e
children 188c86d4a11e
files sqlpython/completion.py sqlpython/sqlpyPlus.py
diffstat 2 files changed, 128 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/sqlpython/completion.py	Fri Oct 09 23:08:50 2009 -0400
+++ b/sqlpython/completion.py	Sun Oct 11 10:03:18 2009 -0400
@@ -40,7 +40,10 @@
     results.sort(cmp=lambda x,y:cmp(x[1],y[1]))
     return results
         
+at_beginning = re.compile(r'^\s*\S+\s*$')
 def whichSegment(statement):
+    if at_beginning.search(statement):
+        return 'beginning'
     results = orderedParseResults(keywords.values(), statement)
     if results:
         return ' '.join(results[-1][0])
@@ -59,4 +62,115 @@
         result.append(letter)
     result.reverse()
     return ''.join(result)
-    
\ No newline at end of file
+    
+
+reserved = '''
+      access
+     add
+     all
+     alter
+     and
+     any
+     as
+     asc
+     audit
+     between
+     by
+     char
+     check
+     cluster
+     column
+     comment
+     compress
+     connect
+     create
+     current
+     date
+     decimal
+     default
+     delete
+     desc
+     distinct
+     drop
+     else
+     exclusive
+     exists
+     file
+     float
+     for
+     from
+     grant
+     group
+     having
+     identified
+     immediate
+     in
+     increment
+     index
+     initial
+     insert
+     integer
+     intersect
+     into
+     is
+     level
+     like
+     lock
+     long
+     maxextents
+     minus
+     mlslabel
+     mode
+     modify
+     noaudit
+     nocompress
+     not
+     nowait
+     null
+     number
+     of
+     offline
+     on
+     online
+     option
+     or
+     order
+     pctfree
+     prior
+     privileges
+     public
+     raw
+     rename
+     resource
+     revoke
+     row
+     rowid
+     rownum
+     rows
+     select
+     session
+     set
+     share
+     size
+     smallint
+     start
+     successful
+     synonym
+     sysdate
+     table
+     then
+     to
+     trigger
+     uid
+     union
+     unique
+     update
+     user
+     validate
+     values
+     varchar
+     varchar2
+     view
+     whenever
+     where
+     with '''.split()
\ No newline at end of file
--- a/sqlpython/sqlpyPlus.py	Fri Oct 09 23:08:50 2009 -0400
+++ b/sqlpython/sqlpyPlus.py	Sun Oct 11 10:03:18 2009 -0400
@@ -546,27 +546,24 @@
         (username, schemas) = self.metadata()
         segment = completion.whichSegment(line)
         text = text.upper()
-        completions = []
-        if segment == 'select':
+        print segment
+        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
-        if segment in ('from', 'update', 'insert into'):
+        elif segment in ('from', 'update', 'insert into'):
             completions = [t for t in schemas[username].table_names if t.startswith(text)]
-            #tableNames = completion.tableNamesFromFromClause(line)
-        if segment == 'where':
-            completions = []
-            for table_name in completion.tableNamesFromFromClause(line):
-                table = schemas[username].schema[table_name]
-                completions.extend(c['name'] for c in table.columns.values())
-                completions.extend('%s.%s' % (table_name, c['name']) for c in table.columns.values())
-                completions = [c for c in completions if c.startswith(text)]
-            
-        if not segment:
-            stmt = "SELECT object_name FROM all_objects WHERE object_name LIKE '%s%%'"
-            completions = self.select_scalar_list(stmt % (text))
+        elif segment == 'beginning':
+            completions = [n for n in self.get_names() if n.startswith('do_')] + [
+                           'insert', 'update', 'delete', 'drop', 'alter', 'begin', 'declare', 'create']
+            print completions
+            completions = [c for c in completions if c.startswith(text)]     
+        else:
+            completions = [r for r in completion.reserved if r.startswith(text)]
+                            
+                           
         return completions
-
+    
     columnlistPattern = pyparsing.SkipTo(pyparsing.CaselessKeyword('from'))('columns') + \
                         pyparsing.SkipTo(pyparsing.stringEnd)('remainder')