annotate runtime/autoload/sqlcomplete.vim @ 2888:2763fe7844f6

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