Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Version 9.0

Version 9.0
- This change removes some of the support for tables with spaces in their names in order to simplify the regexes used to pull out query table aliases for more robust table name and column name code completion.
- Full support for "table names with spaces" can be added in again after 7.3.

Version 8.0
- Incorrectly re-executed the g:ftplugin_sql_omni_key_right and :ftplugin_sql_omni_key_left  when drilling in and out of a column list for a table.
  • Loading branch information...
commit d815ef725868e2ee96d6ce915f4ee310151ddac2 1 parent 0ed3756
@dfishburn dfishburn authored committed
Showing with 42 additions and 20 deletions.
  1. +42 −20 plugin/sqlcomplete.vim
View
62 plugin/sqlcomplete.vim
@@ -1,14 +1,23 @@
" Vim OMNI completion script for SQL
" Language: SQL
" Maintainer: David Fishburn <dfishburn dot vim at gmail dot com>
-" Version: 7.0
-" Last Change: 2009 Nov 17
+" Version: 9.0
+" Last Change: 2010 May 13
" Usage: For detailed help
" ":help sql.txt"
" or ":help ft-sql-omni"
-" or readVIMRUNTIME/doc/sql.txt
+" or read $VIMRUNTIME/doc/sql.txt
" History
+" Version 9.0
+" This change removes some of the support for tables with spaces in their
+" names in order to simplify the regexes used to pull out query table
+" aliases for more robust table name and column name code completion.
+" Full support for "table names with spaces" can be added in again
+" after 7.3.
+" Version 8.0
+" Incorrectly re-executed the g:ftplugin_sql_omni_key_right and g:ftplugin_sql_omni_key_left
+" when drilling in and out of a column list for a table.
" Version 7.0
" Better handling of object names
" Version 6.0
@@ -250,7 +259,7 @@ function! sqlcomplete#Complete(findstart, base)
" 1. Check if the dbext plugin has the option turned
" on to even allow owners
" 2. Based on 1, if the user is showing a table list
- " and the DrillIntoTable (using <C-Right>) then
+ " and the DrillIntoTable (using <Right>) then
" this will be owner.table. In this case, we can
" check to see the table.column exists in the
" cached table list. If it does, then we have
@@ -390,13 +399,14 @@ function! sqlcomplete#DrillIntoTable()
call sqlcomplete#Map('column')
" C-Y, makes the currently highlighted entry active
" and trigger the omni popup to be redisplayed
- call feedkeys("\<C-Y>\<C-X>\<C-O>")
+ call feedkeys("\<C-Y>\<C-X>\<C-O>", 'n')
else
- if has('win32')
- " If the popup is not visible, simple perform the normal
- " <C-Right> behaviour
- exec "normal! \<C-Right>"
- endif
+ " If the popup is not visible, simple perform the normal
+ " key behaviour.
+ " Must use exec since they key must be preceeded by "\"
+ " or feedkeys will simply push each character of the string
+ " rather than the "key press".
+ exec 'call feedkeys("\'.g:ftplugin_sql_omni_key_right.'", "n")'
endif
return ""
endfunction
@@ -408,11 +418,12 @@ function! sqlcomplete#DrillOutOfColumns()
" Trigger the omni popup to be redisplayed
call feedkeys("\<C-X>\<C-O>")
else
- if has('win32')
- " If the popup is not visible, simple perform the normal
- " <C-Left> behaviour
- exec "normal! \<C-Left>"
- endif
+ " If the popup is not visible, simple perform the normal
+ " key behaviour.
+ " Must use exec since they key must be preceeded by "\"
+ " or feedkeys will simply push each character of the string
+ " rather than the "key press".
+ exec 'call feedkeys("\'.g:ftplugin_sql_omni_key_left.'", "n")'
endif
return ""
endfunction
@@ -628,17 +639,28 @@ function! s:SQLCGetColumns(table_name, list_type)
if query =~? '^\(select\|update\|delete\)'
let found = 1
" \(\(\<\w\+\>\)\.\)\? -
- " 'from.\{-}' - Starting at the from clause
+ " '\c\(from\|join\|,\).\{-}' - Starting at the from clause (case insensitive)
" '\zs\(\(\<\w\+\>\)\.\)\?' - Get the owner name (optional)
" '\<\w\+\>\ze' - Get the table name
" '\s\+\<'.table_name.'\>' - Followed by the alias
" '\s*\.\@!.*' - Cannot be followed by a .
" '\(\<where\>\|$\)' - Must be followed by a WHERE clause
" '.*' - Exclude the rest of the line in the match
+ " let table_name_new = matchstr(@y,
+ " \ '\c\(from\|join\|,\).\{-}'.
+ " \ '\zs\(\("\|\[\)\?.\{-}\("\|\]\)\.\)\?'.
+ " \ '\("\|\[\)\?.\{-}\("\|\]\)\?\ze'.
+ " \ '\s\+\%(as\s\+\)\?\<'.
+ " \ matchstr(table_name, '.\{-}\ze\.\?$').
+ " \ '\>'.
+ " \ '\s*\.\@!.*'.
+ " \ '\(\<where\>\|$\)'.
+ " \ '.*'
+ " \ )
let table_name_new = matchstr(@y,
- \ '\cfrom.\{-}'.
- \ '\zs\(\("\|\[\)\?.\{-}\("\|\]\)\.\)\?'.
- \ '\("\|\[\)\?.\{-}\("\|\]\)\?\ze'.
+ \ '\c\(\<from\>\|\<join\>\|,\)\s*'.
+ \ '\zs\(\("\|\[\)\?\w\+\("\|\]\)\?\.\)\?'.
+ \ '\("\|\[\)\?\w\+\("\|\]\)\?\ze'.
\ '\s\+\%(as\s\+\)\?\<'.
\ matchstr(table_name, '.\{-}\ze\.\?$').
\ '\>'.
@@ -649,7 +671,7 @@ function! s:SQLCGetColumns(table_name, list_type)
if table_name_new != ''
let table_alias = table_name
- let table_name = table_name_new
+ let table_name = matchstr( table_name_new, '^\(.*\.\)\?\zs.*\ze' )
let list_idx = index(s:tbl_name, table_name, 0, &ignorecase)
if list_idx > -1
Please sign in to comment.
Something went wrong with that request. Please try again.