annotate runtime/autoload/sqlcomplete.vim @ 2002:071166147fc5 v7.2.299

updated for version 7.2-299
author vimboss
date Tue, 17 Nov 2009 15:08:26 +0000
parents 18ee39301b82
children 7bc41231fbc7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
844
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
1 " Vim OMNI completion script for SQL
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
2 " Language: SQL
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
3 " Maintainer: David Fishburn <fishburn@ianywhere.com>
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1126
diff changeset
4 " Version: 6.0
18ee39301b82 updated for version 7.2a
vimboss
parents: 1126
diff changeset
5 " Last Change: Thu 03 Apr 2008 10:37:54 PM Eastern Daylight Time
844
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
6 " Usage: For detailed help
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
7 " ":help sql.txt"
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
8 " or ":help ft-sql-omni"
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
9 " or read $VIMRUNTIME/doc/sql.txt
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
10
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
11 " Set completion with CTRL-X CTRL-O to autoloaded function.
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
12 " This check is in place in case this script is
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
13 " sourced directly instead of using the autoload feature.
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
14 if exists('&omnifunc')
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
15 " Do not set the option if already set since this
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
16 " results in an E117 warning.
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
17 if &omnifunc == ""
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
18 setlocal omnifunc=sqlcomplete#Complete
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
19 endif
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
20 endif
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
21
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
22 if exists('g:loaded_sql_completion')
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
23 finish
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
24 endif
1126
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
25 let g:loaded_sql_completion = 50
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
26
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
27 " Maintains filename of dictionary
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
28 let s:sql_file_table = ""
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
29 let s:sql_file_procedure = ""
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
30 let s:sql_file_view = ""
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
31
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
32 " Define various arrays to be used for caching
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
33 let s:tbl_name = []
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
34 let s:tbl_alias = []
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
35 let s:tbl_cols = []
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
36 let s:syn_list = []
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
37 let s:syn_value = []
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
38
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
39 " Used in conjunction with the syntaxcomplete plugin
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
40 let s:save_inc = ""
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
41 let s:save_exc = ""
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
42 if exists('g:omni_syntax_group_include_sql')
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
43 let s:save_inc = g:omni_syntax_group_include_sql
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
44 endif
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
45 if exists('g:omni_syntax_group_exclude_sql')
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
46 let s:save_exc = g:omni_syntax_group_exclude_sql
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
47 endif
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
48
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
49 " Used with the column list
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
50 let s:save_prev_table = ""
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
51
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
52 " Default the option to verify table alias
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
53 if !exists('g:omni_sql_use_tbl_alias')
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
54 let g:omni_sql_use_tbl_alias = 'a'
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
55 endif
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
56 " Default syntax items to precache
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
57 if !exists('g:omni_sql_precache_syntax_groups')
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
58 let g:omni_sql_precache_syntax_groups = [
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
59 \ 'syntax',
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
60 \ 'sqlKeyword',
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
61 \ 'sqlFunction',
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
62 \ 'sqlOption',
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
63 \ 'sqlType',
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
64 \ 'sqlStatement'
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
65 \ ]
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
66 endif
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 819
diff changeset
67 " Set ignorecase to the ftplugin standard
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 819
diff changeset
68 if !exists('g:omni_sql_ignorecase')
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 819
diff changeset
69 let g:omni_sql_ignorecase = &ignorecase
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 819
diff changeset
70 endif
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 819
diff changeset
71 " During table completion, should the table list also
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 819
diff changeset
72 " include the owner name
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 819
diff changeset
73 if !exists('g:omni_sql_include_owner')
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 819
diff changeset
74 let g:omni_sql_include_owner = 0
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 819
diff changeset
75 if exists('g:loaded_dbext')
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 819
diff changeset
76 if g:loaded_dbext >= 300
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 819
diff changeset
77 " New to dbext 3.00, by default the table lists include the owner
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 819
diff changeset
78 " name of the table. This is used when determining how much of
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 819
diff changeset
79 " whatever has been typed should be replaced as part of the
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 819
diff changeset
80 " code replacement.
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 819
diff changeset
81 let g:omni_sql_include_owner = 1
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 819
diff changeset
82 endif
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 819
diff changeset
83 endif
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 819
diff changeset
84 endif
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
85
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
86 " This function is used for the 'omnifunc' option.
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
87 function! sqlcomplete#Complete(findstart, base)
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
88
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
89 " Default to table name completion
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
90 let compl_type = 'table'
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
91 " Allow maps to specify what type of object completion they want
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
92 if exists('b:sql_compl_type')
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
93 let compl_type = b:sql_compl_type
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
94 endif
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
95
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
96 " First pass through this function determines how much of the line should
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
97 " be replaced by whatever is chosen from the completion list
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
98 if a:findstart
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
99 " Locate the start of the item, including "."
844
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
100 let line = getline('.')
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
101 let start = col('.') - 1
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
102 let lastword = -1
844
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
103 let begindot = 0
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
104 " Check if the first character is a ".", for column completion
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
105 if line[start - 1] == '.'
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
106 let begindot = 1
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
107 endif
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
108 while start > 0
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1126
diff changeset
109 if line[start - 1] =~ '\(\w\|\s\+\)'
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
110 let start -= 1
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 819
diff changeset
111 elseif line[start - 1] =~ '\.' &&
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 819
diff changeset
112 \ compl_type =~ 'column\|table\|view\|procedure'
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 819
diff changeset
113 " If lastword has already been set for column completion
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 819
diff changeset
114 " break from the loop, since we do not also want to pickup
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 819
diff changeset
115 " a table name if it was also supplied.
1126
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
116 if lastword != -1 && compl_type == 'column'
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 819
diff changeset
117 break
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 819
diff changeset
118 endif
844
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
119 " If column completion was specified stop at the "." if
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
120 " a . was specified, otherwise, replace all the way up
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
121 " to the owner name (if included).
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
122 if lastword == -1 && compl_type == 'column' && begindot == 1
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
123 let lastword = start
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
124 endif
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 819
diff changeset
125 " If omni_sql_include_owner = 0, do not include the table
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 819
diff changeset
126 " name as part of the substitution, so break here
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 819
diff changeset
127 if lastword == -1 &&
844
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
128 \ compl_type =~ 'table\|view\|procedure\column_csv' &&
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 819
diff changeset
129 \ g:omni_sql_include_owner == 0
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 819
diff changeset
130 let lastword = start
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 819
diff changeset
131 break
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 819
diff changeset
132 endif
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
133 let start -= 1
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
134 else
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
135 break
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
136 endif
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
137 endwhile
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
138
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
139 " Return the column of the last word, which is going to be changed.
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
140 " Remember the text that comes before it in s:prepended.
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
141 if lastword == -1
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
142 let s:prepended = ''
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
143 return start
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
144 endif
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
145 let s:prepended = strpart(line, start, lastword - start)
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
146 return lastword
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
147 endif
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
148
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
149 " Second pass through this function will determine what data to put inside
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
150 " of the completion list
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
151 " s:prepended is set by the first pass
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
152 let base = s:prepended . a:base
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
153
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
154 " Default the completion list to an empty list
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
155 let compl_list = []
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
156
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
157 " Default to table name completion
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
158 let compl_type = 'table'
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
159 " Allow maps to specify what type of object completion they want
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
160 if exists('b:sql_compl_type')
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
161 let compl_type = b:sql_compl_type
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
162 unlet b:sql_compl_type
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
163 endif
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
164
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
165 if compl_type == 'tableReset'
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
166 let compl_type = 'table'
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
167 let base = ''
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
168 endif
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
169
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
170 if compl_type == 'table' ||
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
171 \ compl_type == 'procedure' ||
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
172 \ compl_type == 'view'
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
173
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
174 " This type of completion relies upon the dbext.vim plugin
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
175 if s:SQLCCheck4dbext() == -1
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
176 return []
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
177 endif
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
178
1126
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
179 " Allow the user to override the dbext plugin to specify whether
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
180 " the owner/creator should be included in the list
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1126
diff changeset
181 if g:loaded_dbext >= 300
18ee39301b82 updated for version 7.2a
vimboss
parents: 1126
diff changeset
182 let saveSetting = DB_listOption('dict_show_owner')
18ee39301b82 updated for version 7.2a
vimboss
parents: 1126
diff changeset
183 exec 'DBSetOption dict_show_owner='.(g:omni_sql_include_owner==1?'1':'0')
1126
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
184 endif
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
185
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
186 let compl_type_uc = substitute(compl_type, '\w\+', '\u&', '')
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
187 if s:sql_file_{compl_type} == ""
1126
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
188 let s:sql_file_{compl_type} = DB_getDictionaryName(compl_type_uc)
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
189 endif
1126
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
190 let s:sql_file_{compl_type} = DB_getDictionaryName(compl_type_uc)
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
191 if s:sql_file_{compl_type} != ""
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
192 if filereadable(s:sql_file_{compl_type})
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
193 let compl_list = readfile(s:sql_file_{compl_type})
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
194 endif
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
195 endif
1126
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
196
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1126
diff changeset
197 if g:loaded_dbext > 300
18ee39301b82 updated for version 7.2a
vimboss
parents: 1126
diff changeset
198 exec 'DBSetOption dict_show_owner='.saveSetting
18ee39301b82 updated for version 7.2a
vimboss
parents: 1126
diff changeset
199 endif
1126
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
200 elseif compl_type =~? 'column'
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
201
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
202 " This type of completion relies upon the dbext.vim plugin
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
203 if s:SQLCCheck4dbext() == -1
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
204 return []
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
205 endif
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
206
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
207 if base == ""
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
208 " The last time we displayed a column list we stored
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
209 " the table name. If the user selects a column list
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
210 " without a table name of alias present, assume they want
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
211 " the previous column list displayed.
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
212 let base = s:save_prev_table
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
213 endif
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
214
1126
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
215 let owner = ''
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
216 let column = ''
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
217
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
218 if base =~ '\.'
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
219 " Check if the owner/creator has been specified
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
220 let owner = matchstr( base, '^\zs.*\ze\..*\..*' )
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
221 let table = matchstr( base, '^\(.*\.\)\?\zs.*\ze\..*' )
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
222 let column = matchstr( base, '.*\.\zs.*' )
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
223
1126
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
224 " It is pretty well impossible to determine if the user
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
225 " has entered:
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
226 " owner.table
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
227 " table.column_prefix
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
228 " So there are a couple of things we can do to mitigate
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
229 " this issue.
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
230 " 1. Check if the dbext plugin has the option turned
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
231 " on to even allow owners
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
232 " 2. Based on 1, if the user is showing a table list
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
233 " and the DrillIntoTable (using <C-Right>) then
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
234 " this will be owner.table. In this case, we can
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
235 " check to see the table.column exists in the
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
236 " cached table list. If it does, then we have
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
237 " determined the user has actually chosen
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
238 " owner.table, not table.column_prefix.
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
239 let found = -1
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
240 if g:omni_sql_include_owner == 1 && owner == ''
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
241 if filereadable(s:sql_file_table)
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
242 let tbl_list = readfile(s:sql_file_table)
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
243 let found = index( tbl_list, ((table != '')?(table.'.'):'').column)
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
244 endif
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
245 endif
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
246 " If the table.column was found in the table list, we can safely assume
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
247 " the owner was not provided and shift the items appropriately.
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
248 " OR
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
249 " If the user has indicated not to use table owners at all and
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
250 " the base ends in a '.' we know they are not providing a column
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
251 " name, so we can shift the items appropriately.
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
252 if found != -1 || (g:omni_sql_include_owner == 0 && base !~ '\.$')
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
253 let owner = table
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
254 let table = column
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
255 let column = ''
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
256 endif
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
257 else
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
258 let table = base
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
259 endif
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
260
1126
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
261 " Get anything after the . and consider this the table name
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
262 " If an owner has been specified, then we must consider the
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
263 " base to be a partial column name
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
264 " let base = matchstr( base, '^\(.*\.\)\?\zs.*' )
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
265
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
266 if table != ""
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
267 let s:save_prev_table = base
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
268 let list_type = ''
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
269
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
270 if compl_type == 'column_csv'
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
271 " Return one array element, with a comma separated
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
272 " list of values instead of multiple array entries
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
273 " for each column in the table.
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
274 let list_type = 'csv'
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
275 endif
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
276
1126
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
277 let compl_list = s:SQLCGetColumns(table, list_type)
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
278 if column != ''
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
279 " If no column prefix has been provided and the table
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
280 " name was provided, append it to each of the items
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
281 " returned.
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
282 let compl_list = map(compl_list, "table.'.'.v:val")
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
283 if owner != ''
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
284 " If an owner has been provided append it to each of the
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
285 " items returned.
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
286 let compl_list = map(compl_list, "owner.'.'.v:val")
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
287 endif
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
288 else
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
289 let base = ''
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
290 endif
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
291
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
292 if compl_type == 'column_csv'
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
293 " Join the column array into 1 single element array
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
294 " but make the columns column separated
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
295 let compl_list = [join(compl_list, ', ')]
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
296 endif
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
297 endif
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
298 elseif compl_type == 'resetCache'
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
299 " Reset all cached items
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
300 let s:tbl_name = []
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
301 let s:tbl_alias = []
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
302 let s:tbl_cols = []
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
303 let s:syn_list = []
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
304 let s:syn_value = []
844
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
305
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
306 let msg = "All SQL cached items have been removed."
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
307 call s:SQLCWarningMsg(msg)
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
308 " Leave time for the user to read the error message
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
309 :sleep 2
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
310 else
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
311 let compl_list = s:SQLCGetSyntaxList(compl_type)
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
312 endif
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
313
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
314 if base != ''
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
315 " Filter the list based on the first few characters the user
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
316 " entered
1126
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
317 let expr = 'v:val '.(g:omni_sql_ignorecase==1?'=~?':'=~#').' "\\(^'.base.'\\|\\([^.]*\\)\\?'.base.'\\)"'
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 819
diff changeset
318 let compl_list = filter(deepcopy(compl_list), expr)
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
319 endif
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
320
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
321 if exists('b:sql_compl_savefunc') && b:sql_compl_savefunc != ""
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
322 let &omnifunc = b:sql_compl_savefunc
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
323 endif
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
324
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
325 return compl_list
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
326 endfunc
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
327
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
328 function! sqlcomplete#PreCacheSyntax(...)
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
329 let syn_group_arr = []
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
330 if a:0 > 0
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
331 let syn_group_arr = a:1
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
332 else
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
333 let syn_group_arr = g:omni_sql_precache_syntax_groups
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
334 endif
1126
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
335 " For each group specified in the list, precache all
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
336 " the sytnax items.
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
337 if !empty(syn_group_arr)
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
338 for group_name in syn_group_arr
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
339 call s:SQLCGetSyntaxList(group_name)
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
340 endfor
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
341 endif
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
342 endfunction
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
343
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
344 function! sqlcomplete#Map(type)
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
345 " Tell the SQL plugin what you want to complete
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
346 let b:sql_compl_type=a:type
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
347 " Record previous omnifunc, if the SQL completion
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
348 " is being used in conjunction with other filetype
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
349 " completion plugins
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
350 if &omnifunc != "" && &omnifunc != 'sqlcomplete#Complete'
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
351 " Record the previous omnifunc, the plugin
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
352 " will automatically set this back so that it
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
353 " does not interfere with other ftplugins settings
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
354 let b:sql_compl_savefunc=&omnifunc
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
355 endif
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
356 " Set the OMNI func for the SQL completion plugin
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
357 let &omnifunc='sqlcomplete#Complete'
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
358 endfunction
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
359
844
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
360 function! sqlcomplete#DrillIntoTable()
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
361 " If the omni popup window is visible
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
362 if pumvisible()
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
363 call sqlcomplete#Map('column')
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
364 " C-Y, makes the currently highlighted entry active
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
365 " and trigger the omni popup to be redisplayed
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
366 call feedkeys("\<C-Y>\<C-X>\<C-O>")
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
367 else
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
368 if has('win32')
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
369 " If the popup is not visible, simple perform the normal
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
370 " <C-Right> behaviour
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
371 exec "normal! \<C-Right>"
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
372 endif
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
373 endif
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
374 return ""
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
375 endfunction
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
376
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
377 function! sqlcomplete#DrillOutOfColumns()
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
378 " If the omni popup window is visible
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
379 if pumvisible()
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
380 call sqlcomplete#Map('tableReset')
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
381 " Trigger the omni popup to be redisplayed
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
382 call feedkeys("\<C-X>\<C-O>")
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
383 else
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
384 if has('win32')
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
385 " If the popup is not visible, simple perform the normal
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
386 " <C-Left> behaviour
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
387 exec "normal! \<C-Left>"
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
388 endif
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
389 endif
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
390 return ""
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
391 endfunction
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
392
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
393 function! s:SQLCWarningMsg(msg)
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
394 echohl WarningMsg
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
395 echomsg a:msg
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
396 echohl None
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
397 endfunction
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
398
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
399 function! s:SQLCErrorMsg(msg)
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
400 echohl ErrorMsg
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
401 echomsg a:msg
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
402 echohl None
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
403 endfunction
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
404
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
405 function! s:SQLCGetSyntaxList(syn_group)
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
406 let syn_group = a:syn_group
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
407 let compl_list = []
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
408
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
409 " Check if we have already cached the syntax list
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
410 let list_idx = index(s:syn_list, syn_group, 0, &ignorecase)
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
411 if list_idx > -1
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
412 " Return previously cached value
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
413 let compl_list = s:syn_value[list_idx]
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
414 else
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
415 " Request the syntax list items from the
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
416 " syntax completion plugin
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
417 if syn_group == 'syntax'
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
418 " Handle this special case. This allows the user
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
419 " to indicate they want all the syntax items available,
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
420 " so do not specify a specific include list.
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
421 let g:omni_syntax_group_include_sql = ''
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
422 else
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
423 " The user has specified a specific syntax group
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
424 let g:omni_syntax_group_include_sql = syn_group
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
425 endif
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
426 let g:omni_syntax_group_exclude_sql = ''
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
427 let syn_value = OmniSyntaxList()
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
428 let g:omni_syntax_group_include_sql = s:save_inc
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
429 let g:omni_syntax_group_exclude_sql = s:save_exc
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
430 " Cache these values for later use
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
431 let s:syn_list = add( s:syn_list, syn_group )
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
432 let s:syn_value = add( s:syn_value, syn_value )
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
433 let compl_list = syn_value
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
434 endif
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
435
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
436 return compl_list
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
437 endfunction
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
438
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
439 function! s:SQLCCheck4dbext()
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
440 if !exists('g:loaded_dbext')
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
441 let msg = "The dbext plugin must be loaded for dynamic SQL completion"
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
442 call s:SQLCErrorMsg(msg)
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
443 " Leave time for the user to read the error message
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
444 :sleep 2
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
445 return -1
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1126
diff changeset
446 elseif g:loaded_dbext < 600
18ee39301b82 updated for version 7.2a
vimboss
parents: 1126
diff changeset
447 let msg = "The dbext plugin must be at least version 5.30 " .
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
448 \ " for dynamic SQL completion"
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
449 call s:SQLCErrorMsg(msg)
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
450 " Leave time for the user to read the error message
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
451 :sleep 2
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
452 return -1
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
453 endif
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
454 return 1
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
455 endfunction
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
456
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
457 function! s:SQLCAddAlias(table_name, table_alias, cols)
844
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
458 " Strip off the owner if included
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
459 let table_name = matchstr(a:table_name, '\%(.\{-}\.\)\?\zs\(.*\)' )
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
460 let table_alias = a:table_alias
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
461 let cols = a:cols
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
462
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
463 if g:omni_sql_use_tbl_alias != 'n'
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
464 if table_alias == ''
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
465 if 'da' =~? g:omni_sql_use_tbl_alias
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
466 if table_name =~ '_'
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
467 " Treat _ as separators since people often use these
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
468 " for word separators
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
469 let save_keyword = &iskeyword
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
470 setlocal iskeyword-=_
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
471
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
472 " Get the first letter of each word
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
473 " [[:alpha:]] is used instead of \w
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
474 " to catch extended accented characters
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
475 "
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
476 let table_alias = substitute(
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
477 \ table_name,
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
478 \ '\<[[:alpha:]]\+\>_\?',
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
479 \ '\=strpart(submatch(0), 0, 1)',
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
480 \ 'g'
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
481 \ )
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
482 " Restore original value
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
483 let &iskeyword = save_keyword
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
484 elseif table_name =~ '\u\U'
844
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
485 let table_alias = substitute(
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
486 \ table_name, '\(\u\)\U*', '\1', 'g')
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
487 else
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
488 let table_alias = strpart(table_name, 0, 1)
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
489 endif
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
490 endif
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
491 endif
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
492 if table_alias != ''
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
493 " Following a word character, make sure there is a . and no spaces
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
494 let table_alias = substitute(table_alias, '\w\zs\.\?\s*$', '.', '')
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
495 if 'a' =~? g:omni_sql_use_tbl_alias && a:table_alias == ''
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
496 let table_alias = inputdialog("Enter table alias:", table_alias)
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
497 endif
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
498 endif
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
499 if table_alias != ''
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
500 let cols = substitute(cols, '\<\w', table_alias.'&', 'g')
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
501 endif
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
502 endif
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
503
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
504 return cols
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
505 endfunction
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
506
1126
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
507 function! s:SQLCGetObjectOwner(object)
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
508 " The owner regex matches a word at the start of the string which is
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
509 " followed by a dot, but doesn't include the dot in the result.
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1126
diff changeset
510 " ^ - from beginning of line
18ee39301b82 updated for version 7.2a
vimboss
parents: 1126
diff changeset
511 " \("\|\[\)\? - ignore any quotes
18ee39301b82 updated for version 7.2a
vimboss
parents: 1126
diff changeset
512 " \zs - start the match now
18ee39301b82 updated for version 7.2a
vimboss
parents: 1126
diff changeset
513 " .\{-} - get owner name
18ee39301b82 updated for version 7.2a
vimboss
parents: 1126
diff changeset
514 " \ze - end the match
18ee39301b82 updated for version 7.2a
vimboss
parents: 1126
diff changeset
515 " \("\|\[\)\? - ignore any quotes
18ee39301b82 updated for version 7.2a
vimboss
parents: 1126
diff changeset
516 " \. - must by followed by a .
18ee39301b82 updated for version 7.2a
vimboss
parents: 1126
diff changeset
517 " let owner = matchstr( a:object, '^\s*\zs.*\ze\.' )
18ee39301b82 updated for version 7.2a
vimboss
parents: 1126
diff changeset
518 let owner = matchstr( a:object, '^\("\|\[\)\?\zs\.\{-}\ze\("\|\]\)\?\.' )
1126
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
519 return owner
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
520 endfunction
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
521
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
522 function! s:SQLCGetColumns(table_name, list_type)
1126
c5c164b4c95c updated for version 7.1a
vimboss
parents: 844
diff changeset
523 " Check if the table name was provided as part of the column name
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1126
diff changeset
524 let table_name = matchstr(a:table_name, '^["\[\]a-zA-Z0-9_ ]\+\ze\.\?')
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
525 let table_cols = []
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
526 let table_alias = ''
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
527 let move_to_top = 1
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
528
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1126
diff changeset
529 let table_name = substitute(table_name, '\s*\(.\{-}\)\s*$', '\1', 'g')
18ee39301b82 updated for version 7.2a
vimboss
parents: 1126
diff changeset
530
18ee39301b82 updated for version 7.2a
vimboss
parents: 1126
diff changeset
531 " If the table name was given as:
18ee39301b82 updated for version 7.2a
vimboss
parents: 1126
diff changeset
532 " where c.
18ee39301b82 updated for version 7.2a
vimboss
parents: 1126
diff changeset
533 let table_name = substitute(table_name, '^\c\(WHERE\|AND\|OR\)\s\+', '', '')
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 819
diff changeset
534 if g:loaded_dbext >= 300
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
535 let saveSettingAlias = DB_listOption('use_tbl_alias')
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
536 exec 'DBSetOption use_tbl_alias=n'
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
537 endif
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
538
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1126
diff changeset
539 let table_name_stripped = substitute(table_name, '["\[\]]*', '', 'g')
18ee39301b82 updated for version 7.2a
vimboss
parents: 1126
diff changeset
540
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
541 " Check if we have already cached the column list for this table
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
542 " by its name
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1126
diff changeset
543 let list_idx = index(s:tbl_name, table_name_stripped, 0, &ignorecase)
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
544 if list_idx > -1
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1126
diff changeset
545 let table_cols = split(s:tbl_cols[list_idx], '\n')
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
546 else
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
547 " Check if we have already cached the column list for this table
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
548 " by its alias, assuming the table_name provided was actually
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
549 " the alias for the table instead
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
550 " select *
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
551 " from area a
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
552 " where a.
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1126
diff changeset
553 let list_idx = index(s:tbl_alias, table_name_stripped, 0, &ignorecase)
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
554 if list_idx > -1
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1126
diff changeset
555 let table_alias = table_name_stripped
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
556 let table_name = s:tbl_name[list_idx]
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1126
diff changeset
557 let table_cols = split(s:tbl_cols[list_idx], '\n')
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
558 endif
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
559 endif
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
560
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
561 " If we have not found a cached copy of the table
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
562 " And the table ends in a "." or we are looking for a column list
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
563 " if list_idx == -1 && (a:table_name =~ '\.' || b:sql_compl_type =~ 'column')
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
564 " if list_idx == -1 && (a:table_name =~ '\.' || a:list_type =~ 'csv')
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
565 if list_idx == -1
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
566 let saveY = @y
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
567 let saveSearch = @/
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
568 let saveWScan = &wrapscan
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
569 let curline = line(".")
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
570 let curcol = col(".")
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
571
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
572 " Do not let searchs wrap
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
573 setlocal nowrapscan
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
574 " If . was entered, look at the word just before the .
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
575 " We are looking for something like this:
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
576 " select *
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
577 " from customer c
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
578 " where c.
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
579 " So when . is pressed, we need to find 'c'
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
580 "
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
581
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
582 " Search backwards to the beginning of the statement
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
583 " and do NOT wrap
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
584 " exec 'silent! normal! v?\<\(select\|update\|delete\|;\)\>'."\n".'"yy'
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
585 exec 'silent! normal! ?\<\(select\|update\|delete\|;\)\>'."\n"
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
586
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
587 " Start characterwise visual mode
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
588 " Advance right one character
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
589 " Search foward until one of the following:
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
590 " 1. Another select/update/delete statement
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
591 " 2. A ; at the end of a line (the delimiter)
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
592 " 3. The end of the file (incase no delimiter)
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
593 " Yank the visually selected text into the "y register.
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
594 exec 'silent! normal! vl/\(\<select\>\|\<update\>\|\<delete\>\|;\s*$\|\%$\)'."\n".'"yy'
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
595
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
596 let query = @y
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
597 let query = substitute(query, "\n", ' ', 'g')
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
598 let found = 0
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
599
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
600 " if query =~? '^\(select\|update\|delete\)'
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
601 if query =~? '^\(select\)'
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
602 let found = 1
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
603 " \(\(\<\w\+\>\)\.\)\? -
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
604 " 'from.\{-}' - Starting at the from clause
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
605 " '\zs\(\(\<\w\+\>\)\.\)\?' - Get the owner name (optional)
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
606 " '\<\w\+\>\ze' - Get the table name
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
607 " '\s\+\<'.table_name.'\>' - Followed by the alias
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
608 " '\s*\.\@!.*' - Cannot be followed by a .
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
609 " '\(\<where\>\|$\)' - Must be followed by a WHERE clause
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
610 " '.*' - Exclude the rest of the line in the match
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
611 let table_name_new = matchstr(@y,
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
612 \ 'from.\{-}'.
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1126
diff changeset
613 \ '\zs\(\("\|\[\)\?.\{-}\("\|\]\)\.\)\?'.
18ee39301b82 updated for version 7.2a
vimboss
parents: 1126
diff changeset
614 \ '\("\|\[\)\?.\{-}\("\|\]\)\ze'.
844
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
615 \ '\s\+\%(as\s\+\)\?\<'.
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
616 \ matchstr(table_name, '.\{-}\ze\.\?$').
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
617 \ '\>'.
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
618 \ '\s*\.\@!.*'.
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
619 \ '\(\<where\>\|$\)'.
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
620 \ '.*'
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
621 \ )
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1126
diff changeset
622
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
623 if table_name_new != ''
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
624 let table_alias = table_name
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
625 let table_name = table_name_new
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
626
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
627 let list_idx = index(s:tbl_name, table_name, 0, &ignorecase)
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
628 if list_idx > -1
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
629 let table_cols = split(s:tbl_cols[list_idx])
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
630 let s:tbl_name[list_idx] = table_name
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
631 let s:tbl_alias[list_idx] = table_alias
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
632 else
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
633 let list_idx = index(s:tbl_alias, table_name, 0, &ignorecase)
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
634 if list_idx > -1
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
635 let table_cols = split(s:tbl_cols[list_idx])
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
636 let s:tbl_name[list_idx] = table_name
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
637 let s:tbl_alias[list_idx] = table_alias
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
638 endif
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
639 endif
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
640
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
641 endif
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
642 else
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
643 " Simply assume it is a table name provided with a . on the end
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
644 let found = 1
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
645 endif
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
646
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
647 let @y = saveY
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
648 let @/ = saveSearch
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
649 let &wrapscan = saveWScan
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
650
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
651 " Return to previous location
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
652 call cursor(curline, curcol)
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
653
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
654 if found == 0
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 819
diff changeset
655 if g:loaded_dbext > 300
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
656 exec 'DBSetOption use_tbl_alias='.saveSettingAlias
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
657 endif
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
658
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
659 " Not a SQL statement, do not display a list
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
660 return []
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
661 endif
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
662 endif
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
663
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
664 if empty(table_cols)
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
665 " Specify silent mode, no messages to the user (tbl, 1)
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
666 " Specify do not comma separate (tbl, 1, 1)
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
667 let table_cols_str = DB_getListColumn(table_name, 1, 1)
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
668
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
669 if table_cols_str != ""
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
670 let s:tbl_name = add( s:tbl_name, table_name )
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
671 let s:tbl_alias = add( s:tbl_alias, table_alias )
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
672 let s:tbl_cols = add( s:tbl_cols, table_cols_str )
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1126
diff changeset
673 let table_cols = split(table_cols_str, '\n')
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
674 endif
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
675
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
676 endif
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
677
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 819
diff changeset
678 if g:loaded_dbext > 300
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
679 exec 'DBSetOption use_tbl_alias='.saveSettingAlias
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
680 endif
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
681
844
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
682 " If the user has asked for a comma separate list of column
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
683 " values, ask the user if they want to prepend each column
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
684 " with a tablename alias.
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
685 if a:list_type == 'csv' && !empty(table_cols)
844
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
686 let cols = join(table_cols, ', ')
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
687 let cols = s:SQLCAddAlias(table_name, table_alias, cols)
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
688 let table_cols = [cols]
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
689 endif
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
690
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
691 return table_cols
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
692 endfunction
1f929f3ca806 updated for version 7.0c03
vimboss
parents:
diff changeset
693