annotate runtime/autoload/sqlcomplete.vim @ 6973:7b35ee02b3c5 v7.4.804

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