Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Version 6.0

This release is in conjunction with the dbext.vim 6.0 release.  It adds SQL completion support of objects which contain spaces "my table".
  • Loading branch information...
commit 70f2b19f062a00e4cd453cf7a7724f3a9e7fb64b 1 parent d8af887
authored vim-scripts committed

Showing 1 changed file with 37 additions and 35 deletions. Show diff stats Hide diff stats

  1. 72  plugin/sqlcomplete.vim
72  plugin/sqlcomplete.vim
... ...
@@ -1,8 +1,8 @@
1 1
 " Vim OMNI completion script for SQL
2 2
 " Language:    SQL
3 3
 " Maintainer:  David Fishburn <fishburn@ianywhere.com>
4  
-" Version:     5.0
5  
-" Last Change: Mon Jun 05 2006 3:30:04 PM
  4
+" Version:     6.0
  5
+" Last Change: Thu 03 Apr 2008 10:37:54 PM Eastern Daylight Time
6 6
 " Usage:       For detailed help
7 7
 "              ":help sql.txt" 
8 8
 "              or ":help ft-sql-omni" 
@@ -106,7 +106,7 @@ function! sqlcomplete#Complete(findstart, base)
106 106
             let begindot = 1
107 107
         endif
108 108
         while start > 0
109  
-            if line[start - 1] =~ '\w'
  109
+            if line[start - 1] =~ '\(\w\|\s\+\)'
110 110
                 let start -= 1
111 111
             elseif line[start - 1] =~ '\.' && 
112 112
                         \ compl_type =~ 'column\|table\|view\|procedure'
@@ -178,11 +178,10 @@ function! sqlcomplete#Complete(findstart, base)
178 178
 
179 179
         " Allow the user to override the dbext plugin to specify whether
180 180
         " the owner/creator should be included in the list
181  
-        let saved_dbext_show_owner      = 1
182  
-        if exists('g:dbext_default_dict_show_owner')
183  
-            let saved_dbext_show_owner  = g:dbext_default_dict_show_owner
  181
+        if g:loaded_dbext >= 300
  182
+            let saveSetting = DB_listOption('dict_show_owner')
  183
+            exec 'DBSetOption dict_show_owner='.(g:omni_sql_include_owner==1?'1':'0')
184 184
         endif
185  
-        let g:dbext_default_dict_show_owner = g:omni_sql_include_owner
186 185
 
187 186
         let compl_type_uc = substitute(compl_type, '\w\+', '\u&', '')
188 187
         if s:sql_file_{compl_type} == ""
@@ -192,18 +191,12 @@ function! sqlcomplete#Complete(findstart, base)
192 191
         if s:sql_file_{compl_type} != ""
193 192
             if filereadable(s:sql_file_{compl_type})
194 193
                 let compl_list = readfile(s:sql_file_{compl_type})
195  
-                " let dic_list = readfile(s:sql_file_{compl_type})
196  
-                " if !empty(dic_list)
197  
-                "     for elem in dic_list
198  
-                "         let kind = (compl_type=='table'?'m':(compl_type=='procedure'?'f':'v'))
199  
-                "         let item = {'word':elem, 'menu':elem, 'kind':kind, 'info':compl_type}
200  
-                "         let compl_list += [item]
201  
-                "     endfor
202  
-                " endif
203 194
             endif
204 195
         endif
205 196
 
206  
-        let g:dbext_default_dict_show_owner = saved_dbext_show_owner
  197
+        if g:loaded_dbext > 300
  198
+            exec 'DBSetOption dict_show_owner='.saveSetting
  199
+        endif
207 200
     elseif compl_type =~? 'column'
208 201
 
209 202
         " This type of completion relies upon the dbext.vim plugin
@@ -450,8 +443,8 @@ function! s:SQLCCheck4dbext()
450 443
         " Leave time for the user to read the error message
451 444
         :sleep 2
452 445
         return -1
453  
-    elseif g:loaded_dbext < 300
454  
-        let msg = "The dbext plugin must be at least version 3.00 " .
  446
+    elseif g:loaded_dbext < 600
  447
+        let msg = "The dbext plugin must be at least version 5.30 " .
455 448
                     \ " for dynamic SQL completion"
456 449
         call s:SQLCErrorMsg(msg)
457 450
         " Leave time for the user to read the error message
@@ -514,34 +507,42 @@ endfunction
514 507
 function! s:SQLCGetObjectOwner(object) 
515 508
     " The owner regex matches a word at the start of the string which is
516 509
     " followed by a dot, but doesn't include the dot in the result.
517  
-    " ^    - from beginning of line
518  
-    " "\?  - ignore any quotes
519  
-    " \zs  - start the match now
520  
-    " \w\+ - get owner name
521  
-    " \ze  - end the match
522  
-    " "\?  - ignore any quotes
523  
-    " \.   - must by followed by a .
524  
-    let owner = matchstr( a:object, '^"\?\zs\w\+\ze"\?\.' )
  510
+    " ^           - from beginning of line
  511
+    " \("\|\[\)\? - ignore any quotes
  512
+    " \zs         - start the match now
  513
+    " .\{-}       - get owner name
  514
+    " \ze         - end the match
  515
+    " \("\|\[\)\? - ignore any quotes
  516
+    " \.          - must by followed by a .
  517
+    " let owner = matchstr( a:object, '^\s*\zs.*\ze\.' )
  518
+    let owner = matchstr( a:object, '^\("\|\[\)\?\zs\.\{-}\ze\("\|\]\)\?\.' )
525 519
     return owner
526 520
 endfunction 
527 521
 
528 522
 function! s:SQLCGetColumns(table_name, list_type)
529 523
     " Check if the table name was provided as part of the column name
530  
-    let table_name   = matchstr(a:table_name, '^[a-zA-Z0-9_]\+\ze\.\?')
  524
+    let table_name   = matchstr(a:table_name, '^["\[\]a-zA-Z0-9_ ]\+\ze\.\?')
531 525
     let table_cols   = []
532 526
     let table_alias  = ''
533 527
     let move_to_top  = 1
534 528
 
  529
+    let table_name   = substitute(table_name, '\s*\(.\{-}\)\s*$', '\1', 'g')
  530
+
  531
+    " If the table name was given as:
  532
+    "     where c.
  533
+    let table_name   = substitute(table_name, '^\c\(WHERE\|AND\|OR\)\s\+', '', '')
535 534
     if g:loaded_dbext >= 300
536 535
         let saveSettingAlias = DB_listOption('use_tbl_alias')
537 536
         exec 'DBSetOption use_tbl_alias=n'
538 537
     endif
539 538
 
  539
+    let table_name_stripped = substitute(table_name, '["\[\]]*', '', 'g')
  540
+
540 541
     " Check if we have already cached the column list for this table
541 542
     " by its name
542  
-    let list_idx = index(s:tbl_name, table_name, 0, &ignorecase)
  543
+    let list_idx = index(s:tbl_name, table_name_stripped, 0, &ignorecase)
543 544
     if list_idx > -1
544  
-        let table_cols = split(s:tbl_cols[list_idx])
  545
+        let table_cols = split(s:tbl_cols[list_idx], '\n')
545 546
     else
546 547
         " Check if we have already cached the column list for this table 
547 548
         " by its alias, assuming the table_name provided was actually
@@ -549,11 +550,11 @@ function! s:SQLCGetColumns(table_name, list_type)
549 550
         "     select *
550 551
         "       from area a
551 552
         "      where a.
552  
-        let list_idx = index(s:tbl_alias, table_name, 0, &ignorecase)
  553
+        let list_idx = index(s:tbl_alias, table_name_stripped, 0, &ignorecase)
553 554
         if list_idx > -1
554  
-            let table_alias = table_name
  555
+            let table_alias = table_name_stripped
555 556
             let table_name  = s:tbl_name[list_idx]
556  
-            let table_cols  = split(s:tbl_cols[list_idx])
  557
+            let table_cols  = split(s:tbl_cols[list_idx], '\n')
557 558
         endif
558 559
     endif
559 560
 
@@ -609,8 +610,8 @@ function! s:SQLCGetColumns(table_name, list_type)
609 610
              " '.*'  - Exclude the rest of the line in the match
610 611
              let table_name_new = matchstr(@y, 
611 612
                          \ 'from.\{-}'.
612  
-                         \ '\zs\(\(\<\w\+\>\)\.\)\?'.
613  
-                         \ '\<\w\+\>\ze'.
  613
+                         \ '\zs\(\("\|\[\)\?.\{-}\("\|\]\)\.\)\?'.
  614
+                         \ '\("\|\[\)\?.\{-}\("\|\]\)\ze'.
614 615
                          \ '\s\+\%(as\s\+\)\?\<'.
615 616
                          \ matchstr(table_name, '.\{-}\ze\.\?$').
616 617
                          \ '\>'.
@@ -618,6 +619,7 @@ function! s:SQLCGetColumns(table_name, list_type)
618 619
                          \ '\(\<where\>\|$\)'.
619 620
                          \ '.*'
620 621
                          \ )
  622
+
621 623
              if table_name_new != ''
622 624
                  let table_alias = table_name
623 625
                  let table_name  = table_name_new
@@ -668,7 +670,7 @@ function! s:SQLCGetColumns(table_name, list_type)
668 670
             let s:tbl_name  = add( s:tbl_name,  table_name )
669 671
             let s:tbl_alias = add( s:tbl_alias, table_alias )
670 672
             let s:tbl_cols  = add( s:tbl_cols,  table_cols_str )
671  
-            let table_cols  = split(table_cols_str)
  673
+            let table_cols  = split(table_cols_str, '\n')
672 674
         endif
673 675
 
674 676
     endif

0 notes on commit 70f2b19

Please sign in to comment.
Something went wrong with that request. Please try again.