annotate runtime/doc/sql.txt @ 856:8cd729851562 v7.0g

updated for version 7.0g
author vimboss
date Sun, 30 Apr 2006 18:54:39 +0000
parents d3bbb5dd3913
children 4bac29d27e2f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
1 *sql.txt* For Vim version 7.0g. Last change: Wed Apr 26 2006 3:05:33 PM
720
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
2
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
3 by David Fishburn
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
4
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
5 This is a filetype plugin to work with SQL files.
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
6
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
7 The Structured Query Language (SQL) is a standard which specifies statements
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
8 that allow a user to interact with a relational database. Vim includes
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
9 features for navigation, indentation and syntax highlighting.
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
10
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
11 1. Navigation |sql-navigation|
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
12 1.1 Matchit |sql-matchit|
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
13 1.2 Text Object Motions |sql-object-motions|
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
14 1.3 Predefined Object Motions |sql-predefined-objects|
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
15 1.4 Macros |sql-macros|
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
16 2. SQL Dialects |sql-dialects|
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
17 2.1 SQLSetType |SQLSetType|
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
18 2.2 SQL Dialect Default |sql-type-default|
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
19 3. Adding new SQL Dialects |sql-adding-dialects|
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
20 4. OMNI SQL Completion |sql-completion|
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
21 4.1 Static mode |sql-completion-static|
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
22 4.2 Dynamic mode |sql-completion-dynamic|
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
23 4.3 Tutorial |sql-completion-tutorial|
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
24 4.3.1 Complete Tables |sql-completion-tables|
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
25 4.3.2 Complete Columns |sql-completion-columns|
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
26 4.3.3 Complete Procedures |sql-completion-procedures|
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
27 4.3.4 Complete Views |sql-completion-views|
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
28 4.4 Completion Customization |sql-completion-customization|
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
29 4.5 SQL Maps |sql-completion-maps|
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
30 4.6 Using with other filetypes |sql-completion-filetypes|
720
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
31
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
32 ==============================================================================
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
33 1. Navigation *sql-navigation*
720
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
34
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
35 The SQL ftplugin provides a number of options to assist with file
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
36 navigation.
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
37
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
38
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
39 1.1 Matchit *sql-matchit*
720
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
40 -----------
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
41 The matchit plugin (http://www.vim.org/scripts/script.php?script_id=39)
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
42 provides many additional features and can be customized for different
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
43 languages. The matchit plugin is configured by defining a local
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
44 buffer variable, b:match_words. Pressing the % key while on various
720
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
45 keywords will move the cursor to its match. For example, if the cursor
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
46 is on an "if", pressing % will cycle between the "else", "elseif" and
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
47 "end if" keywords.
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
48
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
49 The following keywords are supported: >
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
50 if
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
51 elseif | elsif
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
52 else [if]
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
53 end if
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
54
720
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
55 [while condition] loop
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
56 leave
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
57 break
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
58 continue
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
59 exit
720
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
60 end loop
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
61
720
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
62 for
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
63 leave
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
64 break
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
65 continue
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
66 exit
720
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
67 end loop
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
68
720
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
69 do
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
70 statements
720
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
71 doend
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
72
720
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
73 case
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
74 when
720
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
75 when
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
76 default
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
77 end case
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
78
720
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
79 merge
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
80 when not matched
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
81 when matched
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
82
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
83 create[ or replace] procedure|function|event
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
84 returns
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
85
720
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
86
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
87 1.2 Text Object Motions *sql-object-motions*
720
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
88 -----------------------
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
89 Vim has a number of predefined keys for working with text |object-motions|.
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
90 This filetype plugin attempts to translate these keys to maps which make sense
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
91 for the SQL language.
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
92
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
93 The following |Normal| mode and |Visual| mode maps exist (when you edit a SQL
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
94 file): >
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
95 ]] move forward to the next 'begin'
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
96 [[ move backwards to the previous 'begin'
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
97 ][ move forward to the next 'end'
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
98 [] move backwards to the previous 'end'
720
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
99
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
100
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
101 1.3 Predefined Object Motions *sql-predefined-objects*
720
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
102 -----------------------------
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
103 Most relational databases support various standard features, tables, indices,
720
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
104 triggers and stored procedures. Each vendor also has a variety of proprietary
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
105 objects. The next set of maps have been created to help move between these
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
106 objects. Depends on which database vendor you are using, the list of objects
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
107 must be configurable. The filetype plugin attempts to define many of the
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
108 standard objects, plus many additional ones. In order to make this as
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
109 flexible as possible, you can override the list of objects from within your
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
110 |vimrc| with the following: >
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
111 let g:ftplugin_sql_objects = 'function,procedure,event,table,trigger' .
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
112 \ ',schema,service,publication,database,datatype,domain' .
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
113 \ ',index,subscription,synchronization,view,variable'
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
114
720
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
115 The following |Normal| mode and |Visual| mode maps have been created which use
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
116 the above list: >
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
117 ]} move forward to the next 'create <object name>'
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
118 [{ move backward to the previous 'create <object name>'
720
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
119
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
120 Repeatedly pressing ]} will cycle through each of these create statements: >
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
121 create table t1 (
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
122 ...
720
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
123 );
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
124
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
125 create procedure p1
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
126 begin
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
127 ...
720
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
128 end;
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
129
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
130 create index i1 on t1 (c1);
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
131
720
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
132 The default setting for g:ftplugin_sql_objects is: >
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
133 let g:ftplugin_sql_objects = 'function,procedure,event,' .
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
134 \ '\\(existing\\\\|global\\s\\+temporary\\s\\+\\)\\\{,1}' .
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
135 \ 'table,trigger' .
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
136 \ ',schema,service,publication,database,datatype,domain' .
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
137 \ ',index,subscription,synchronization,view,variable'
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
138
720
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
139 The above will also handle these cases: >
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
140 create table t1 (
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
141 ...
720
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
142 );
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
143 create existing table t2 (
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
144 ...
720
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
145 );
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
146 create global temporary table t3 (
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
147 ...
720
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
148 );
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
149
720
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
150 By default, the ftplugin only searches for CREATE statements. You can also
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
151 override this via your |vimrc| with the following: >
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
152 let g:ftplugin_sql_statements = 'create,alter'
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
153
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
154 The filetype plugin defines three types of comments: >
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
155 1. --
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
156 2. //
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
157 3. /*
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
158 *
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
159 */
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
160
720
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
161 The following |Normal| mode and |Visual| mode maps have been created to work
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
162 with comments: >
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
163 ]" move forward to the beginning of a comment
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
164 [" move forward to the end of a comment
720
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
165
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
166
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
167
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
168 1.4 Macros *sql-macros*
720
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
169 ----------
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
170 Vim's feature to find macro definitions, |'define'|, is supported using this
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
171 regular expression: >
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
172 \c\<\(VARIABLE\|DECLARE\|IN\|OUT\|INOUT\)\>
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
173
720
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
174 This addresses the following code: >
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
175 CREATE VARIABLE myVar1 INTEGER;
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
176
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
177 CREATE PROCEDURE sp_test(
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
178 IN myVar2 INTEGER,
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
179 OUT myVar3 CHAR(30),
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
180 INOUT myVar4 NUMERIC(20,0)
720
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
181 )
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
182 BEGIN
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
183 DECLARE myVar5 INTEGER;
720
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
184
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
185 SELECT c1, c2, c3
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
186 INTO myVar2, myVar3, myVar4
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
187 FROM T1
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
188 WHERE c4 = myVar1;
720
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
189 END;
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
190
720
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
191 Place your cursor on "myVar1" on this line: >
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
192 WHERE c4 = myVar1;
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
193 ^
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
194
720
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
195 Press any of the following keys: >
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
196 [d
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
197 [D
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
198 [CTRL-D
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
199
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
200
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
201 ==============================================================================
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
202 2. SQL Dialects *sql-dialects* *sql-types*
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
203 *sybase* *TSQL* *Transact-SQL*
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
204 *sqlanywhere*
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
205 *oracle* *plsql* *sqlj*
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
206 *sqlserver*
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
207 *mysql* *postgress* *psql*
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
208 *informix*
720
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
209
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
210 All relational databases support SQL. There is a portion of SQL that is
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
211 portable across vendors (ex. CREATE TABLE, CREATE INDEX), but there is a
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
212 great deal of vendor specific extensions to SQL. Oracle supports the
720
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
213 "CREATE OR REPLACE" syntax, column defaults specified in the CREATE TABLE
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
214 statement and the procedural language (for stored procedures and triggers).
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
215
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
216 The default Vim distribution ships with syntax highlighting based on Oracle's
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
217 PL/SQL. The default SQL indent script works for Oracle and SQL Anywhere.
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
218 The default filetype plugin works for all vendors and should remain vendor
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
219 neutral, but extendable.
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
220
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
221 Vim currently has support for a variety of different vendors, currently this
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
222 is via syntax scripts. Unfortunately, to flip between different syntax rules
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
223 you must either create:
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
224 1. New filetypes
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
225 2. Custom autocmds
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
226 3. Manual steps / commands
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
227
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
228 The majority of people work with only one vendor's database product, it would
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
229 be nice to specify a default in your |vimrc|.
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
230
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
231
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
232 2.1 SQLSetType *sqlsettype* *SQLSetType*
720
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
233 --------------
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
234 For the people that work with many different databases, it would be nice to be
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
235 able to flip between the various vendors rules (indent, syntax) on a per
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
236 buffer basis, at any time. The ftplugin/sql.vim file defines this function: >
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
237 SQLSetType
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
238
720
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
239 Executing this function without any parameters will set the indent and syntax
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
240 scripts back to their defaults, see |sql-type-default|. If you have turned
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
241 off Vi's compatibility mode, |'compatible'|, you can use the <Tab> key to
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
242 complete the optional parameter.
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
243
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
244 After typing the function name and a space, you can use the completion to
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
245 supply a parameter. The function takes the name of the Vim script you want to
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
246 source. Using the |cmdline-completion| feature, the SQLSetType function will
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
247 search the |'runtimepath'| for all Vim scripts with a name containing 'sql'.
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
248 This takes the guess work out of the spelling of the names. The following are
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
249 examples: >
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
250 :SQLSetType
720
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
251 :SQLSetType sqloracle
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
252 :SQLSetType sqlanywhere
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
253 :SQLSetType sqlinformix
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
254 :SQLSetType mysql
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
255
720
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
256 The easiest approach is to the use <Tab> character which will first complete
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
257 the command name (SQLSetType), after a space and another <Tab>, display a list
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
258 of available Vim script names: >
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
259 :SQL<Tab><space><Tab>
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
260
720
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
261
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
262 2.2 SQL Dialect Default *sql-type-default*
720
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
263 -----------------------
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
264 As mentioned earlier, the default syntax rules for Vim is based on Oracle
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
265 (PL/SQL). You can override this default by placing one of the following in
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
266 your |vimrc|: >
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
267 let g:sql_type_default = 'sqlanywhere'
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
268 let g:sql_type_default = 'sqlinformix'
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
269 let g:sql_type_default = 'mysql'
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
270
720
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
271 If you added the following to your |vimrc|: >
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
272 let g:sql_type_default = 'sqlinformix'
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
273
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
274 The next time edit a SQL file the following scripts will be automatically
720
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
275 loaded by Vim: >
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
276 ftplugin/sql.vim
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
277 syntax/sqlinformix.vim
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
278 indent/sql.vim
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
279 >
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
280 Notice indent/sqlinformix.sql was not loaded. There is no indent file
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
281 for Informix, Vim loads the default files if the specified files does not
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
282 exist.
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
283
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
284
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
285 ==============================================================================
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
286 3. Adding new SQL Dialects *sql-adding-dialects*
720
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
287
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
288 If you begin working with a SQL dialect which does not have any customizations
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
289 available with the default Vim distribution you can check http://www.vim.org
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
290 to see if any customization currently exist. If not, you can begin by cloning
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
291 an existing script. Read |filetype-plugins| for more details.
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
292
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
293 To help identify these scripts, try to create the files with a "sql" prefix.
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
294 If you decide you wish to create customizations for the SQLite database, you
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
295 can create any of the following: >
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
296 Unix
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
297 ~/.vim/syntax/sqlite.vim
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
298 ~/.vim/indent/sqlite.vim
720
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
299 Windows
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
300 $VIM/vimfiles/syntax/sqlite.vim
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
301 $VIM/vimfiles/indent/sqlite.vim
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
302
720
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
303 No changes are necessary to the SQLSetType function. It will automatically
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
304 pickup the new SQL files and load them when you issue the SQLSetType command.
720
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
305
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
306
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
307 ==============================================================================
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
308 4. OMNI SQL Completion *sql-completion*
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
309 *omni-sql-completion*
720
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
310
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
311 Vim 7 includes a code completion interface and functions which allows plugin
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
312 developers to build in code completion for any language. Vim 7 includes
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
313 code completion for the SQL language.
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
314
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
315 There are two modes to the SQL completion plugin, static and dynamic. The
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
316 static mode populates the popups with the data generated from current syntax
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
317 highlight rules. The dynamic mode populates the popups with data retrieved
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
318 directly from a database. This includes, table lists, column lists,
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
319 procedures names and more.
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
320
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
321 4.1 Static Mode *sql-completion-static*
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
322 ---------------
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
323 The static popups created contain items defined by the active syntax rules
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
324 while editing a file with a filetype of SQL. The plugin defines (by default)
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
325 various maps to help the user refine the list of items to be displayed.
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
326 The defaults static maps are: >
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
327 imap <buffer> <C-C>a <C-\><C-O>:call sqlcomplete#Map('syntax')<CR><C-X><C-O>
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
328 imap <buffer> <C-C>k <C-\><C-O>:call sqlcomplete#Map('sqlKeyword')<CR><C-X><C-O>
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
329 imap <buffer> <C-C>f <C-\><C-O>:call sqlcomplete#Map('sqlFunction')<CR><C-X><C-O>
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
330 imap <buffer> <C-C>o <C-\><C-O>:call sqlcomplete#Map('sqlOption')<CR><C-X><C-O>
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
331 imap <buffer> <C-C>T <C-\><C-O>:call sqlcomplete#Map('sqlType')<CR><C-X><C-O>
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
332 imap <buffer> <C-C>s <C-\><C-O>:call sqlcomplete#Map('sqlStatement')<CR><C-X><C-O>
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
333
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
334 The static maps (which are based on the syntax highlight groups) follow this
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
335 format: >
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
336 imap <buffer> <C-C>k <C-\><C-O>:call sqlcomplete#Map('sqlKeyword')<CR><C-X><C-O>
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
337
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
338 This command breaks down as: >
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
339 imap - Create an insert map
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
340 <buffer> - Only for this buffer
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
341 <C-C>k - Your choice of key map
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
342 <C-\><C-O> - Execute one command, return to Insert mode
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
343 :call sqlcomplete#Map( - Allows the SQL completion plugin to perform some
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
344 housekeeping functions to allow it to be used in
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
345 conjunction with other completion plugins.
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
346 Indicate which item you want the SQL completion
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
347 plugin to complete.
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
348 In this case we are asking the plugin to display
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
349 items from the syntax highlight group
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
350 'sqlKeyword'.
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
351 You can view a list of highlight group names to
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
352 choose from by executing the
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
353 :syntax list
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
354 command while editing a SQL file.
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
355 'sqlKeyword' - Display the items for the sqlKeyword highlight
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
356 group
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
357 )<CR> - Execute the :let command
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
358 <C-X><C-O> - Trigger the standard omni completion key stroke.
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
359 Passing in 'sqlKeyword' instructs the SQL
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
360 completion plugin to populate the popup with
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
361 items from the sqlKeyword highlight group. The
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
362 plugin will also cache this result until Vim is
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
363 restarted. The syntax list is retrieved using
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
364 the syntaxcomplete plugin.
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
365
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
366 Using the 'syntax' keyword is a special case. This instructs the
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
367 syntaxcomplete plugin to retrieve all syntax items. So this will effectively
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
368 work for any of Vim's SQL syntax files. At the time of writing this includes
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
369 10 different syntax files for the different dialects of SQL (see section 3
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
370 above, |sql-dialects|).
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
371
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
372 Here are some examples of the entries which are pulled from the syntax files: >
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
373 All
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
374 - Contains the contents of all syntax highlight groups
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
375 Statements
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
376 - Select, Insert, Update, Delete, Create, Alter, ...
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
377 Functions
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
378 - Min, Max, Trim, Round, Date, ...
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
379 Keywords
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
380 - Index, Database, Having, Group, With
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
381 Options
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
382 - Isolation_level, On_error, Qualify_owners, Fire_triggers, ...
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
383 Types
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
384 - Integer, Char, Varchar, Date, DateTime, Timestamp, ...
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
385
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
386
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
387 4.2 Dynamic Mode *sql-completion-dynamic*
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
388 ----------------
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
389 Dynamic mode populates the popups with data directly from a database. In
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
390 order for the dynamic feature to be enabled you must have the dbext.vim
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
391 plugin installed, (http://vim.sourceforge.net/script.php?script_id=356).
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
392
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
393 Dynamic mode is used by several features of the SQL completion plugin.
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
394 After installing the dbext plugin see the dbext-tutorial for additional
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
395 configuration and usage. The dbext plugin allows the SQL completion plugin
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
396 to display a list of tables, procedures, views and columns. >
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
397 Table List
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
398 - All tables for all schema owners
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
399 Procedure List
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
400 - All stored procedures for all schema owners
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
401 View List
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
402 - All stored procedures for all schema owners
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
403 Column List
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
404 - For the selected table, the columns that are part of the table
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
405
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
406 To enable the popup, while in INSERT mode, use the following key combinations
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
407 for each group (where <C-C> means hold the CTRL key down while pressing
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
408 the space bar):
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
409 Table List - <C-C>t
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
410 - <C-X><C-O> (the default map assumes tables)
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
411 Stored Procedure List - <C-C>p
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
412 View List - <C-C>v
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
413 Column List - <C-C>c
844
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
414
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
415 Windows platform only - When viewing a popup window displaying the list
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
416 of tables, you can press <C-Right>, this will
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
417 replace the table currently highlighted with
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
418 the column list for that table.
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
419 - When viewing a popup window displaying the list
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
420 of columns, you can press <C-Left>, this will
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
421 replace the column list with the list of tables.
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
422 - This allows you to quickly drill down into a
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
423 table to view it's columns and back again.
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
424
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
425 The SQL completion plugin caches various lists that are displayed in
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
426 the popup window. This makes the re-displaying of these lists very
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
427 fast. If new tables or columns are added to the database it may become
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
428 necessary to clear the plugins cache. The default map for this is: >
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
429 imap <buffer> <C-C>R <C-\><C-O>:call sqlcomplete#Map('ResetCache')<CR><C-X><C-O>
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
430
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
431
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
432 4.3 SQL Tutorial *sql-completion-tutorial*
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
433 ----------------
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
434
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
435 This tutorial is designed to take you through the common features of the SQL
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
436 completion plugin so that: >
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
437 a) You gain familiarity with the plugin
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
438 b) You are introduced to some of the more common features
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
439 c) Show how to customize it to your preferences
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
440 d) Demonstrate "Best of Use" of the plugin (easiest way to configure).
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
441
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
442 First, create a new buffer: >
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
443 :e tutorial.sql
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
444
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
445
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
446 Static features
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
447 ---------------
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
448 To take you through the various lists, simply enter insert mode, hit:
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
449 <C-C>s (show SQL statements)
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
450 At this point, you can page down through the list until you find "select".
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
451 If you are familiar with the item you are looking for, for example you know
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
452 the statement begins with the letter "s". You can type ahead (without the
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
453 quotes) "se" then press:
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
454 <C-Space>t
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
455 Assuming "select" is highlighted in the popup list press <Enter> to choose
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
456 the entry. Now type:
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
457 * fr<C-C>a (show all syntax items)
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
458 choose "from" from the popup list.
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
459
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
460 When writing stored procedures using the "type" list is useful. It contains
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
461 a list of all the database supported types. This may or may not be true
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
462 depending on the syntax file you are using. The SQL Anywhere syntax file
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
463 (sqlanywhere.vim) has support for this: >
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
464 BEGIN
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
465 DECLARE customer_id <C-C>T <-- Choose a type from the list
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
466
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
467
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
468 Dynamic features
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
469 ----------------
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
470 To take advantage of the dynamic features you must first install the
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
471 dbext.vim plugin (http://vim.sourceforge.net/script.php?script_id=356). It
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
472 also comes with a tutorial. From the SQL completion plugin's perspective,
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
473 the main feature dbext provides is a connection to a database. dbext
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
474 connection profiles are the most efficient mechanism to define connection
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
475 information. Once connections have been setup, the SQL completion plugin
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
476 uses the features of dbext in the background to populate the popups.
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
477
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
478 What follows assumes dbext.vim has been correctly configured, a simple test
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
479 is to run the command, :DBListTable. If a list of tables is shown, you know
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
480 dbext.vim is working as expected. If not, please consult the dbext.txt
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
481 documentation.
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
482
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
483 Assuming you have followed the dbext-tutorial you can press <C-C>t to
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
484 display a list of tables. There is a delay while dbext is creating the table
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
485 list. After the list is displayed press <C-W>. This will remove both the
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
486 popup window and the table name already chosen when the list became active. >
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
487
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
488 4.3.1 Table Completion: *sql-completion-tables*
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
489
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
490 Press <C-C>t to display a list of tables from within the database you
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
491 have connected via the dbext plugin.
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
492 NOTE: All of the SQL completion popups support typing a prefix before pressing
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
493 the key map. This will limit the contents of the popup window to just items
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
494 beginning with those characters. >
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
495
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
496 4.3.2 Column Completion: *sql-completion-columns*
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
497
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
498 The SQL completion plugin can also display a list of columns for particular
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
499 tables. The column completion is trigger via <C-C>c.
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
500
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
501 NOTE: The following example uses <C-Right> to trigger a column list while
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
502 the popup window is active. This map is only available on the Windows
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
503 platforms since *nix does not recognize CTRL and the right arrow held down
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
504 together. If you wish to enable this functionality on a *nix platform choose
844
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
505 a key and create one of these mappings (see |sql-completion-maps| for further
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
506 details on where to create this imap): >
844
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
507 imap <buffer> <your_keystroke> <C-R>=sqlcomplete#DrillIntoTable()<CR>
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
508 imap <buffer> <your_keystroke> <C-Y><C-\><C-O>:call sqlcomplete#Map('column')<CR><C-X><C-O>
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
509
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
510 Example of using column completion:
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
511 - Press <C-C>t again to display the list of tables.
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
512 - When the list is displayed in the completion window, press <C-Right>,
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
513 this will replace the list of tables, with a list of columns for the
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
514 table highlighted (after the same short delay).
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
515 - If you press <C-Left>, this will again replace the column list with the
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
516 list of tables. This allows you to drill into tables and column lists
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
517 very quickly.
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
518 - Press <C-Right> again while the same table is highlighted. You will
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
519 notice there is no delay since the column list has been cached. If you
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
520 change the schema of a cached table you can press <C-C>R, which
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
521 clears the SQL completion cache.
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
522 - NOTE: <C-Right> and <C-Left> have been designed to work while the
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
523 completion window is active. If the completion popup window is
844
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
524 not active, a normal <C-Right> or <C-Left> will be executed.
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
525
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
526 Lets look how we can build a SQL statement dynamically. A select statement
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
527 requires a list of columns. There are two ways to build a column list using
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
528 the SQL completion plugin. >
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
529 One column at a time:
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
530 < 1. After typing SELECT press <C-C>t to display a list of tables.
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
531 2. Choose a table from the list.
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
532 3. Press <C-Right> to display a list of columns.
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
533 4. Choose the column from the list and press enter.
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
534 5. Enter a "," and press <C-C>c. Generating a column list
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
535 generally requires having the cursor on a table name. The plugin
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
536 uses this name to determine what table to retrieve the column list.
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
537 In this step, since we are pressing <C-C>c without the cursor
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
538 on a table name the column list displayed will be for the previous
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
539 table. Choose a different column and move on.
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
540 6. Repeat step 5 as often as necessary. >
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
541 All columns for a table:
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
542 < 1. After typing SELECT press <C-C>t to display a list of tables.
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
543 2. Highlight the table you need the column list for.
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
544 3. Press <Enter> to choose the table from the list.
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
545 4. Press <C-C>l to request a comma separated list of all columns
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
546 for this table.
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
547 5. Based on the table name chosen in step 3, the plugin attempts to
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
548 decide on a reasonable table alias. You are then prompted to
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
549 either accept of change the alias. Press OK.
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
550 6. The table name is replaced with the column list of the table is
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
551 replaced with the comma separate list of columns with the alias
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
552 prepended to each of the columns.
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
553 7. Step 3 and 4 can be replaced by pressing <C-C>L, which has
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
554 a <C-Y> embedded in the map to choose the currently highlighted
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
555 table in the list.
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
556
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
557 There is a special provision when writing select statements. Consider the
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
558 following statement: >
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
559 select *
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
560 from customer c,
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
561 contact cn,
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
562 department as dp,
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
563 employee e,
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
564 site_options so
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
565 where c.
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
566
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
567 In INSERT mode after typing the final "c." which is an alias for the
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
568 "customer" table, you can press either <C-C>c or <C-X><C-O>. This will
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
569 popup a list of columns for the customer table. It does this by looking back
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
570 to the beginning of the select statement and finding a list of the tables
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
571 specified in the FROM clause. In this case it notes that in the string
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
572 "customer c", "c" is an alias for the customer table. The optional "AS"
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
573 keyword is also supported, "customer AS c". >
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
574
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
575
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
576 4.3.3 Procedure Completion: *sql-completion-procedures*
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
577
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
578 Similar to the table list, <C-C>p, will display a list of stored
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
579 procedures stored within the database. >
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
580
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
581 4.3.4 View Completion: *sql-completion-views*
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
582
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
583 Similar to the table list, <C-C>v, will display a list of views in the
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
584 database.
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
585
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
586
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
587 4.4 Completion Customization *sql-completion-customization*
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
588 ----------------------------
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
589
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
590 The SQL completion plugin can be customized through various options set in
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
591 your |vimrc|: >
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
592 omni_sql_no_default_maps
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
593 < - Default: This variable is not defined
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
594 - If this variable is defined, no maps are created for OMNI
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
595 completion. See |sql-completion-maps| for further discussion.
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
596 >
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
597 omni_sql_use_tbl_alias
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
598 < - Default: a
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
599 - This setting is only used when generating a comma separated
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
600 column list. By default the map is <C-C>l. When generating
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
601 a column list, an alias can be prepended to the beginning of each
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
602 column, for example: e.emp_id, e.emp_name. This option has three
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
603 settings: >
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
604 n - do not use an alias
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
605 d - use the default (calculated) alias
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
606 a - ask to confirm the alias name
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
607 <
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
608 An alias is determined following a few rules:
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
609 1. If the table name has an '_', then use it as a separator: >
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
610 MY_TABLE_NAME --> MTN
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
611 my_table_name --> mtn
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
612 My_table_NAME --> MtN
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
613 < 2. If the table name does NOT contain an '_', but DOES use
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
614 mixed case then the case is used as a separator: >
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
615 MyTableName --> MTN
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
616 < 3. If the table name does NOT contain an '_', and does NOT
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
617 use mixed case then the first letter of the table is used: >
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
618 mytablename --> m
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
619 MYTABLENAME --> M
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
620
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 834
diff changeset
621 omni_sql_ignorecase
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
622 < - Default: Current setting for|ignorecase|
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
623 - Valid settings are 0 or 1.
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
624 - When entering a few letters before initiating completion, the list
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
625 will be filtered to display only the entries which begin with the
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
626 list of characters. When this option is set to 0, the list will be
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
627 filtered using case sensitivity. >
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
628
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 834
diff changeset
629 omni_sql_include_owner
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
630 < - Default: 0, unless dbext.vim 3.00 has been installed
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
631 - Valid settings are 0 or 1.
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
632 - When completing tables, procedure or views and using dbext.vim 3.00
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
633 or higher the list of objects will also include the owner name.
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
634 When completing these objects and omni_sql_include_owner is enabled
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
635 the owner name will be be replaced. >
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
636
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 834
diff changeset
637 omni_sql_precache_syntax_groups
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
638 < - Default:
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
639 ['syntax','sqlKeyword','sqlFunction','sqlOption','sqlType','sqlStatement']
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
640 - sqlcomplete can be used in conjunction with other completion
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
641 plugins. This is outlined at |sql-completion-filetypes|. When the
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
642 filetype is changed temporarily to SQL, the sqlcompletion plugin
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
643 will cache the syntax groups listed in the List specified in this
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
644 option.
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 834
diff changeset
645 >
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
646
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
647 4.5 SQL Maps *sql-completion-maps*
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
648 ------------
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
649
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
650 The default SQL maps have been described in other sections of this document in
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
651 greater detail. Here is a list of the maps with a brief description of each.
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
652
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
653 Static Maps
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
654 -----------
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
655 These are maps which use populate the completion list using Vim's syntax
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
656 highlighting rules. >
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
657 <C-C>a
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
658 < - Displays all SQL syntax items. >
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
659 <C-C>k
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
660 < - Displays all SQL syntax items defined as 'sqlKeyword'. >
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
661 <C-C>f
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
662 < - Displays all SQL syntax items defined as 'sqlFunction. >
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
663 <C-C>o
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
664 < - Displays all SQL syntax items defined as 'sqlOption'. >
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
665 <C-C>T
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
666 < - Displays all SQL syntax items defined as 'sqlType'. >
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
667 <C-C>s
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
668 < - Displays all SQL syntax items defined as 'sqlStatement'. >
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
669
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
670 Dynamic Maps
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
671 ------------
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 834
diff changeset
672 These are maps which use populate the completion list using the dbext.vim
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 834
diff changeset
673 plugin. >
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
674 <C-C>t
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
675 < - Displays a list of tables. >
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
676 <C-C>p
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
677 < - Displays a list of procedures. >
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
678 <C-C>v
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
679 < - Displays a list of views. >
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
680 <C-C>c
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
681 < - Displays a list of columns for a specific table. >
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
682 <C-C>l
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
683 < - Displays a comma separated list of columns for a specific table. >
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
684 <C-C>L
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
685 < - Displays a comma separated list of columns for a specific table.
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
686 This should only be used when the completion window is active. >
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
687 <C-Right>
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
688 < - Displays a list of columns for the table currently highlighted in
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
689 the completion window. <C-Right> is not recognized on most Unix
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
690 systems, so this maps is only created on the Windows platform.
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
691 If you would like the same feature on Unix, choose a different key
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
692 and make the same map in your vimrc. >
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
693 <C-Left>
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
694 < - Displays the list of tables.
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
695 <C-Left> is not recognized on most Unix systems, so this maps is
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
696 only created on the Windows platform. If you would like the same
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
697 feature on Unix, choose a different key and make the same map in
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
698 your vimrc. >
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
699 <C-C>R
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
700 < - This maps removes all cached items and forces the SQL completion
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
701 to regenerate the list of items.
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
702
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
703 Customizing Maps
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
704 ----------------
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
705 You can create as many additional key maps as you like. Generally, the maps
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
706 will be specifying different syntax highlight groups.
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
707
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
708 If you do not wish the default maps created or the key choices do not work on
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
709 your platform (often a case on *nix) you define the following variable in
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
710 your |vimrc|: >
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
711 let g:omni_sql_no_default_maps = 1
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
712
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
713 Do no edit ftplugin/sql.vim directly! If you change this file your changes
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
714 will be over written on future updates. Vim has a special directory structure
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
715 which allows you to make customizations without changing the files that are
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
716 included with the Vim distribution. If you wish to customize the maps
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
717 create an after/ftplugin/sql.vim (see |after-directory|) and place the same
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
718 maps from the ftplugin/sql.vim in it using your own key strokes. <C-C> was
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
719 chosen since it will work on both Windows and *nix platforms. On the windows
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 810
diff changeset
720 platform you can also use <C-Space> or ALT keys.
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
721
720
e180933b876a updated for version 7.0219
vimboss
parents:
diff changeset
722
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
723 4.6 Using with other filetypes *sql-completion-filetypes*
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
724 ------------------------------
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
725
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
726 Many times SQL can be used with different filetypes. For example Perl, Java,
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
727 PHP, Javascript can all interact with a database. Often you need both the SQL
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
728 completion as well as the completion capabilities for the current language you
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
729 are editing.
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
730
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
731 This can be enabled easily with the following steps (assuming a Perl file): >
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
732 1. :e test.pl
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
733 2. :set filetype=sql
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
734 3. :set ft=perl
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
735
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
736 Step 1
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
737 ------
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
738 Begins by editing a Perl file. Vim automatically sets the filetype to
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
739 "perl". By default, Vim runs the appropriate filetype file
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
740 ftplugin/perl.vim. If you are using the syntax completion plugin by following
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
741 the directions at |ft-syntax-omni| then the |'omnifunc'| option has been set to
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
742 "syntax#Complete". Pressing <C-X><C-O> will display the omni popup containing
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
743 the syntax items for Perl.
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
744
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
745 Step 2
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
746 ------
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
747 Manually setting the filetype to 'sql' will also fire the appropriate filetype
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
748 files ftplugin/sql.vim. This file will define a number of buffer specific
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
749 maps for SQL completion, see |sql-completion-maps|. Now these maps have
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
750 been created and the SQL completion plugin has been initialized. All SQL
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
751 syntax items have been cached in preparation. The SQL filetype script detects
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
752 we are attempting to use two different completion plugins. Since the SQL maps
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
753 begin with <C-C>, the maps will toggle the |'omnifunc'| when in use. So you
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
754 can use <C-X><C-O> to continue using the completion for Perl (using the syntax
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
755 completion plugin) and <C-C> to use the SQL completion features.
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
756
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
757 Step 3
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
758 ------
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
759 Setting the filetype back to Perl sets all the usual "perl" related items back
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
760 as they were.
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
761
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
762
810
9f345c48220b updated for version 7.0c
vimboss
parents: 800
diff changeset
763 vim:tw=78:ts=8:ft=help:norl: