vim-sql-workbench.txt 55.5 KB
Newer Older
C
Cosmin Popescu 已提交
1
vim-sql-workbench.txt
C
Cosmin Popescu 已提交
2

C
Cosmin Popescu 已提交
3
================================================================================
C
Cosmin Popescu 已提交
4 5 6
CONTENTS                                              *vim-sql-workbench-contents*

1. Tutorial...........................................|vim-sql-workbench-tutorial|
C
Cosmin Popescu 已提交
7 8 9 10 11 12 13 14 15 16 17 18
2. Disclaimer.......................................|vim-sql-workbench-disclaimer|
3. Introduction...................................|vim-sql-workbench-introduction|
4. Requirements...................................|vim-sql-workbench-requirements|
5. Connecting to a DBMS...................|vim-sql-workbench-connecting_to_a_dbms|
6. The database explorer.................|vim-sql-workbench-the_database_explorer|
7. The SQL buffer...............................|vim-sql-workbench-the_sql_buffer|
8. SQL commands...................................|vim-sql-workbench-sql_commands|
9. Searching.........................................|vim-sql-workbench-searching|
10. Exporting........................................|vim-sql-workbench-exporting|
11. Variables........................................|vim-sql-workbench-variables|
12. Commands..........................................|vim-sql-workbench-commands|
13. Settings..........................................|vim-sql-workbench-settings|
C
Cosmin Popescu 已提交
19 20

================================================================================
C
Cosmin Popescu 已提交
21
TUTORIAL                                              *vim-sql-workbench-tutorial*
C
Cosmin Popescu 已提交
22 23 24 25 26

The following documentation is quite long. If you don't want to read through
it, here is the quick start:

*   install  from here (http://www.sql-workbench.net/)
C
Cosmin Popescu 已提交
27
*   install your `jdbc` driver for your database see
C
Cosmin Popescu 已提交
28
    here (http://www.sql-workbench.net/)
C
Cosmin Popescu 已提交
29
*   open vim
C
Cosmin Popescu 已提交
30 31 32

Running sql queries against a DBMS:

C
Cosmin Popescu 已提交
33
*   set the `g:sw_config_dir` and `g:sw_exe` variables
C
Cosmin Popescu 已提交
34 35 36 37 38 39
*   open your sql buffer
*   if you have `CtrlP` installed you can do `CtrlP` and then select  and choose your profile
*   otherwise, you can do `:SWSqlBufferConnect` and then in the buffer execute
    `WbConnect` (`<Leader>C-<SPACE>`)
*   go to an sql statement
*   in normal mode, do `<Leader><C-@>` (this is `ctrl` + `space`)
C
Cosmin Popescu 已提交
40 41 42

Opening a database explorer

C
Cosmin Popescu 已提交
43
* 
C
Cosmin Popescu 已提交
44 45
Note:

C
Cosmin Popescu 已提交
46
*   `<my-profile>` is the name of a database profile created in
C
Cosmin Popescu 已提交
47 48 49
    (see here (http://www.sql-workbench.net/manual/profiles.html))

For more detailed explanations, please continue reading this material.
C
Cosmin Popescu 已提交
50

C
Cosmin Popescu 已提交
51 52 53 54 55 56 57 58
================================================================================
DISCLAIMER                                          *vim-sql-workbench-disclaimer*

Please note that this version is no longer compatible with VIM 7. If you
didn't upgraded to VIM 8 yet, then don't install this version. Stick with
5.2.2. But you should consider upgrading your vim anyway. For the
documentation of `5.2.2`, please see here (README-7.md)

C
Cosmin Popescu 已提交
59
================================================================================
C
Cosmin Popescu 已提交
60
INTRODUCTION                                      *vim-sql-workbench-introduction*
C
Cosmin Popescu 已提交
61 62 63 64 65

This is an implementation of SQL Workbench/J (http://www.sql-workbench.net/)
in VIM. It works with any DBMS supported by  (PostgreSQL,
Oracle, SQLite, MySQL, SQL Server etc.). See the complete list
here (http://www.sql-workbench.net/databases.html).
C
Cosmin Popescu 已提交
66 67 68

You can connect to any DBMS directly from VIM.

C
Cosmin Popescu 已提交
69
Features:
C
Cosmin Popescu 已提交
70

C
Cosmin Popescu 已提交
71 72 73
*   database explorer (e.g.: table lists, procedures list, views list, triggers
    list), extensible (you can have your own objects list)
*   SQL buffer with performant autocomplete
C
Cosmin Popescu 已提交
74 75
*   export any sql statement as `text`, `sqlinsert`, `sqlupdate`,
    `sqldeleteinsert`, `xml`, `ods`, `html`, `json`
C
Cosmin Popescu 已提交
76 77 78 79
*   search in object source
*   search in table or views data
*   asynchronous (you can execute any command asynchronous)
*   fully customizable
C
Cosmin Popescu 已提交
80
*   transactions
C
Cosmin Popescu 已提交
81 82 83

CONTENTS:

C
Cosmin Popescu 已提交
84 85 86 87 88 89 90
1.  Requirements
2.  Connecting to a DBMS
3.  The database explorer
4.  The SQL Buffer
5.  SQL commands
6.  Searching
7.  Exporting
C
Cosmin Popescu 已提交
91 92 93 94
8.  Variables
9.  Commands
10. Settings
11. Screen shots
C
Cosmin Popescu 已提交
95

C
Cosmin Popescu 已提交
96
================================================================================
C
Cosmin Popescu 已提交
97
REQUIREMENTS                                      *vim-sql-workbench-requirements*
C
Cosmin Popescu 已提交
98

C
Cosmin Popescu 已提交
99
* *    installed on the machine
C
Cosmin Popescu 已提交
100

C
Cosmin Popescu 已提交
101 102 103
NOTE: this version of `vim-sql-workbench` is not compatible with vim 7 anymore.

Of course you need VIM 8 or above. You also need [](http://www.sql-workbench.net/) installed on your computer. It is
C
Cosmin Popescu 已提交
104 105
platform independent, since  is written in JAVA and it should
work anywhere where VIM works.
C
Cosmin Popescu 已提交
106

C
Cosmin Popescu 已提交
107
Before getting started, you have to set the `g:sw_exe` vim variable. The
C
Cosmin Popescu 已提交
108 109 110
default value is `sqlwbconsole.sh`. Otherwise, just set the value of the
variable to point to your `sqlwbconsole` file. If you are on Windows, it
should be `sqlwbconsole.exe`.
C
Cosmin Popescu 已提交
111

C
Cosmin Popescu 已提交
112 113
Also, if you are on Windows, you have to set the `g:sw_tmp` value in your
`vimrc`. The default value is `/tmp`.
C
Cosmin Popescu 已提交
114

C
Cosmin Popescu 已提交
115 116
If you are on window, your  should be configured to not use
the `jline` (set the `workbench.console.use.jline=false` in your  config file).
C
Cosmin Popescu 已提交
117

C
Cosmin Popescu 已提交
118
================================================================================
C
Cosmin Popescu 已提交
119
CONNECTING TO A DBMS                      *vim-sql-workbench-connecting_to_a_dbms*
C
Cosmin Popescu 已提交
120

C
Cosmin Popescu 已提交
121 122 123 124
 has integration with the `CtrlP` plugin. You can set the
`g:sw_config_dir` variable (which contains the `WbProfiles.xml` file) and then
you open your buffer, open `CtrlP`, select , select
your profile and you can begin sending sql queries to your database.
C
Cosmin Popescu 已提交
125

C
Cosmin Popescu 已提交
126 127 128 129
If you don't have `CtrlP` installed, you can use the `:SWSqlBufferConnect`
command. This will open your buffer and connect it to the .
If you run it without any arguments, the current buffer will be connected with
a  instance.
C
Cosmin Popescu 已提交
130

C
Cosmin Popescu 已提交
131
Example:
C
Cosmin Popescu 已提交
132
>
C
Cosmin Popescu 已提交
133
    :SWSqlBufferConnect ~/Documents/my-buffer.sql
C
Cosmin Popescu 已提交
134
<
C
Cosmin Popescu 已提交
135

C
Cosmin Popescu 已提交
136 137 138 139 140
Once you connected your buffer (either by `CtrlP` or by using
`SWSqlBufferConnect`), a new `sqlwbconsole.sh` process will be launched. This
will have it's own connection and it's own transaction. If you close the
buffer, also the process will be closed. Also, if you do
`:SWSqlBufferDisconnect`, the `sqlwbconsole` instance will be closed.
C
Cosmin Popescu 已提交
141

C
Cosmin Popescu 已提交
142
================================================================================
C
Cosmin Popescu 已提交
143
THE DATABASE EXPLORER                    *vim-sql-workbench-the_database_explorer*
C
Cosmin Popescu 已提交
144 145 146

In order to open a database explorer, you need a profile.

C
Cosmin Popescu 已提交
147 148 149
You can create  profiles, either by using the
GUI, like
here (http://www.sql-workbench.net/manual/profiles.html#profile-intro),
C
Cosmin Popescu 已提交
150
either opening a sql buffer with `SWSqlBufferConnect` and then executing
C
Cosmin Popescu 已提交
151
`WbStoreProfile`.
C
Cosmin Popescu 已提交
152

C
Cosmin Popescu 已提交
153
Once you have your profiles created, you can use `SWDbExplorer` with the
C
Cosmin Popescu 已提交
154 155
desired profile as argument and you will connect to the database.

C
Cosmin Popescu 已提交
156 157
For example,  will open a database explorer using the
profile `myProfile`.
C
Cosmin Popescu 已提交
158

C
Cosmin Popescu 已提交
159 160 161 162 163
The database explorer is composed from three parts: on the top, there is a
list of available shortcuts at any moment. On the bottom left, you will see
the list of objects in your database (the list of tables and views or the list
of procedures or the list of triggers etc.) and on the bottom right, you will
see the selected object desired properties. Like in the second or third screen
C
Cosmin Popescu 已提交
164 165
shot.

C
Cosmin Popescu 已提交
166 167 168 169 170
So, if you want to see the columns of a table, you will have to move the
cursor in the bottom left panel, go to the desired table and press 'C'. This
will display in the right panel the table columns, indices and triggers. If
you want to see its source code, you press 'S' and so on. For all the
available shortcuts, see the top panel.
C
Cosmin Popescu 已提交
171 172 173 174

The database explorer if fully customizable. You can use the existing one and
extend it or you can create your own from scratch.

C
Cosmin Popescu 已提交
175
--------------------------------------------------------------------------------
C
Cosmin Popescu 已提交
176
CREATING A NEW DATABASE EXPLORER FROM SCRATCH *vim-sql-workbench-creating_a_new_database_explorer_from_scratch*
C
Cosmin Popescu 已提交
177

C
Cosmin Popescu 已提交
178 179
The database explorer is loaded from the `resources/dbexplorer.vim` file by
default. If you want to write your own, set the `g:sw_dbexplorer_panel`
C
Cosmin Popescu 已提交
180
variable to point to your own file and that file will be loaded. The file has
C
Cosmin Popescu 已提交
181 182 183
to be a `vimscript` file, since it's going to be sourced and it needs to set
the `g:SW_Tabs` variable. For an example, take a look at the
`resources/dbexplorer.vim` file.
C
Cosmin Popescu 已提交
184

C
Cosmin Popescu 已提交
185 186
The `g:SW_Tabs` has to be a vim dictionary. The keys are the profiles for
which the panel will be applied. `*` profile, means that the options appear on
C
Cosmin Popescu 已提交
187
all profiles. If you want to have separate database explorers for separate
C
Cosmin Popescu 已提交
188 189
profiles, you can create a key in the dictionary for each explorer.

C
Cosmin Popescu 已提交
190
You can also have profiles per type of DBMS. If you have a profile starting
C
Cosmin Popescu 已提交
191
with a `:` or a '^'.
C
Cosmin Popescu 已提交
192

C
Cosmin Popescu 已提交
193 194 195
A `:` means that this options will appear for all the profiles which the DBMS
is of that type. For example `:MySQL` it means that these options will appear
only for `mysql` databases.
C
Cosmin Popescu 已提交
196

C
Cosmin Popescu 已提交
197 198 199
A `^` means that this options will appear for all the profiles for which the
DBMS is not of that type. For example `^PostgreSQL` means that there options
will appear for all databases which are not `PostgreSQL`.
C
Cosmin Popescu 已提交
200

C
Cosmin Popescu 已提交
201 202
For this to work, you have to have the option `g:sw_config_dir` set. The
profile informations are read from the `WbProfiles.xml` file which resides in
C
Cosmin Popescu 已提交
203
this folder. The profile type you can see it in the
C
Cosmin Popescu 已提交
204 205
connection window. It's the driver title.

C
Cosmin Popescu 已提交
206
Starting with version `4.0` you can also have a vimscript function called
C
Cosmin Popescu 已提交
207 208 209 210
instead of a sql query. The function called has to return a string which will
be interpreted as the result of the operation. The function will receive as
parameters the line selected (the complete line which has been selected). In
order to have a function instead of a sql query in the database explorer, the
C
Cosmin Popescu 已提交
211
`command` has to begin with `:`.
C
Cosmin Popescu 已提交
212 213 214

For example:
>
C
Cosmin Popescu 已提交
215
    {'title': 'Data', 'shortcut': 'D', 'command': ':My_function'}
C
Cosmin Popescu 已提交
216
<
C
Cosmin Popescu 已提交
217

C
Cosmin Popescu 已提交
218
When the shortcut D will be pressed, the result will be fetch by calling
C
Cosmin Popescu 已提交
219
`My_function(getline('.'))`
C
Cosmin Popescu 已提交
220

C
Cosmin Popescu 已提交
221 222 223
Of course, the current line is relevant only for when changing a tab. When
changing a tab, the current line will contain whatever value is on the
current line in whatever buffer you are at that moment.
C
Cosmin Popescu 已提交
224 225 226 227 228 229 230 231

The values for each profile, have to be a list which will contain all the
options for the left panel. For example, in the default one, the database
objects, triggers and procedures.

Each list of objects of this list is another dictionary, with the following
keys:

C
Cosmin Popescu 已提交
232 233
*   `title` (the title which will be displayed in the top panel)
*   `shortcut` (the shortcut to access it; please note that you can have several
C
Cosmin Popescu 已提交
234
    letters)
C
Cosmin Popescu 已提交
235 236
*   `command` (the sql command which will be executed when selecting the object)
*   `panels` (a list of options accessible in the right panel for each selected
C
Cosmin Popescu 已提交
237
    object in the left panel)
C
Cosmin Popescu 已提交
238 239 240 241

The panels are also a list of dictionaries. Each element of the list has the
following keys:

C
Cosmin Popescu 已提交
242 243 244 245
*   `title` (the title which will be displayed in the top panel)
*   `shortcut` (the shortcut which will be used to display it)
*   `command` (the sql command which will be executed; please note that the sql
    command should contain the `%object%` string, which will be replaced with
C
Cosmin Popescu 已提交
246
    the name of the selected object)
C
Cosmin Popescu 已提交
247 248 249

Optional, the panels might contain the following keys:

C
Cosmin Popescu 已提交
250
*   `skip_columns` (a list with the column indices from the result set that
C
Cosmin Popescu 已提交
251
    should not be displayed)
C
Cosmin Popescu 已提交
252
*   `hide_header` (if set and `true`, then the header of the result set will not
C
Cosmin Popescu 已提交
253
    be displayed in the bottom right panel)
C
Cosmin Popescu 已提交
254
*   `filetype` (if present, the bottom right panel `filetype` will be set
C
Cosmin Popescu 已提交
255 256 257 258 259 260
    according when selecting an object in the left panel)

NOTES:

1.  In the command that creates the left panel, the object for which you want
    to select the informations in the right panel should always be on the first
C
Cosmin Popescu 已提交
261 262 263
    column. The `%object%` string in the column will be replaced by it.
    Alternatively, you can have `%n%` (n being a number from 0 to the number of
    columns in the left panel). If you have `%n%`, this will be replaced by the
C
Cosmin Popescu 已提交
264 265 266 267 268
    value of that column
2.  The command can contain a comment in the format  at the end.
    Everything following "AFTER" word will be interpreted as a VIM command and
    will be executed after the result has been displayed in the right panel. For
    an example, see the SQL Source panel in the default database explorer vim
C
Cosmin Popescu 已提交
269
    file (`resources/dbexplorer.vim`).
C
Cosmin Popescu 已提交
270 271 272 273 274 275 276 277 278 279
3.  The shortcuts for the left panel (the list of objects) have to be unique.
    They are used to identify the current option selected to be displayed, so
    that the shourtcuts for the left panel are loaded according to the panels.
    However, the shortcuts for the right panel can be the same from one list of
    objects to the other. For example, you can have "O" as shortcut for objects
    list and then for each object you can have "S" for showing the source code.
    Then, you can have "P" for listing the procedures. Again, for each procedure
    you can have again "S" as shortcut for listing the source code of a
    procedure or for something else.

C
Cosmin Popescu 已提交
280
--------------------------------------------------------------------------------
C
Cosmin Popescu 已提交
281
EXTENDING THE DEFAULT DATABASE EXPLORER *vim-sql-workbench-extending_the_default_database_explorer*
C
Cosmin Popescu 已提交
282 283

If you are happy with the default options of the database explorer (which are
C
Cosmin Popescu 已提交
284 285
the same with the ones of ) but you just want to add your
own, you can do so by extending the default database explorer.
C
Cosmin Popescu 已提交
286

C
Cosmin Popescu 已提交
287
This is done by calling the `vimscript` function `sw#dbexplorer#add_tab`. The
C
Cosmin Popescu 已提交
288 289
function takes the following arguments:

C
Cosmin Popescu 已提交
290
*   The profile (the profile for which the option should be active; it can be
C
Cosmin Popescu 已提交
291
    `*` for all profiles)
C
Cosmin Popescu 已提交
292 293 294 295 296 297
*   The title (this is the title that will appear on the top panel)
*   The shortcut (this is the shortcut to access it)
*   The command (this is the SQL command to be sent to the DBMS once this option
    is selected)
*   The list of panels (the list of properties to be displayed in the bottom
    right split for each object from the list)
C
Cosmin Popescu 已提交
298 299 300 301

The list of panels is an array of dictionaries. Each dictionary has the same
keys as indicated in the previous section for the list of panels. For example,
if you want to add the database links for all the profiles, you have to add
C
Cosmin Popescu 已提交
302
this in your `vimrc`:
C
Cosmin Popescu 已提交
303
>
C
Cosmin Popescu 已提交
304
    call sw#dbexplorer#add_tab('oracle', 'DB Links', 'L', 'select db_link, username,
C
Cosmin Popescu 已提交
305 306
    created  from user_db_links;', [{'title': 'Show the host', 'shortcut': 'H',
    'command': "select host from user_db_links where db_link = '%object%'"}])
C
Cosmin Popescu 已提交
307
<
C
Cosmin Popescu 已提交
308

C
Cosmin Popescu 已提交
309 310 311 312 313
Now on all your oracle profiles, you will have an extra option. Every time
when you click "L" in normal mode, in the bottom left panel you will have a
list of database links from your schema. For each link, you can move the
cursor on top of it and click H. You will see in the right panel the source of
the link.
C
Cosmin Popescu 已提交
314

C
Cosmin Popescu 已提交
315
Every time when "L" is clicked, `vim-sqlworkbench` sends the  command to the DBMS. The result will be
C
Cosmin Popescu 已提交
316 317 318 319
a list of database links displayed in the bottom left panel.  When you move
your cursor on top of one of this links and press "H", the plugin sends to
your DBMS . The result is displayed in the right panel.

C
Cosmin Popescu 已提交
320 321 322 323 324 325 326 327 328 329 330 331
You can also add a panel to an existing tab, using the
`sw#dbexplorer#add_panel` function. The function takes the following arguments:

*   The profile (the profile for which the option should be active; it can be
    `*` for all profiles)
*   The tab shortcut (is the shortcut identifying the tab for which to add this
    panel)
*   The title (this is the title that will appear on the top panel)
*   The shortcut (this is the shortcut to access it after you accessed the tab)
*   The command (this is the SQL command to be sent to the DBMS once this option
    is selected

C
Cosmin Popescu 已提交
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381
##Events

The database explorer has events to which you can hook a function to be
executed before the command is executed or after the result is received. If
you hook to the before event, your function will receive as a parameter the
command being set to a server and it must return the modified command. If you
hoon to the after event, your function will receive the response from the
server (an array of lines) and can modify it. It has to return the result
which will be displayed in the left or right panel (a new list of lines).

To hook on the tab events, you can use the function
`sw#dbexplorer#add_tab_event`. The arguments are:

*   the shortcut of the tab
*   the event type (`after` or `before`)
*   the function name

Example:
>
    function! BeforeTabObjects(command)
        return "show tables"
    endfunction
    function! AfterTabObjects(result)
        let result = []
        for line in a:result
            call add(result, substitute(line, '\v^TABLE_NAME[ \s\t]*$', 'Tables', 'g'))
        endfor
        return  result
    endfunction
    call sw#dbexplorer#add_tab_event('O', 'before', 'BeforeTabObjects')
    call sw#dbexplorer#add_tab_event('O', 'after', 'AfterTabObjects')
<

After executing this example, when you select the Objects tab in the database
explorer, the command executed is going to be , instead of
`WbList`, which is the default for objects. Then, when the result is returned,
the line `TABLE_NAME` is going to be replaces with the text "Tables".

To hook on panel events, you can use the function
`sw#dbexplorer#add_panel_event`. The arguments are:

*   the shortcut of the tab
*   the shortcut of the panel
*   the type of event (`after` or `before`)
*   the function name

For an example on how to use this function, see the `resources/dbexplorer.vim`
file (the last line) and the `autoload/sw/dbexplorer.vim` file to see the
function hook definition.

C
Cosmin Popescu 已提交
382
================================================================================
C
Cosmin Popescu 已提交
383
THE SQL BUFFER                                  *vim-sql-workbench-the_sql_buffer*
C
Cosmin Popescu 已提交
384

C
Cosmin Popescu 已提交
385
The SQL buffer is a normal `vim` buffer from which you can send SQL commands
C
Cosmin Popescu 已提交
386
to your DBMS and in which you can use the user completion (&lt;C-x&gt;&lt;C-u&gt;) to have
C
Cosmin Popescu 已提交
387 388 389
intellisense autocompletion.

You can connect an opened vim buffer to a server using the
C
Cosmin Popescu 已提交
390 391 392
`SWSqlBufferConnect` command. Or, you can open a buffer which will be directly
connected to a server by specifying the path to the buffer. For example
.
C
Cosmin Popescu 已提交
393 394 395 396

Once in an sql buffer, you have several ways to execute commands against your
DBMS:

C
Cosmin Popescu 已提交
397 398 399
*   execute the current SQL
*   execute the selected statement
*   execute all statements
C
Cosmin Popescu 已提交
400 401

All the shortcuts for these commands are fully customizable. But to do this,
C
Cosmin Popescu 已提交
402
you cannot just map the commands in `vimrc`. This is because these shortcuts
C
Cosmin Popescu 已提交
403 404
are mapped local to the sql buffer, or to the result sets buffer. If you want
to change the default shortcuts, you need to define the
C
Cosmin Popescu 已提交
405 406 407
`g:sw_shortcuts_sql_buffer_statement` variable or the
`g:sw_shortcuts_sql_results` variable. This variables should point each to a
`vimscript` file which will define the mappings.
C
Cosmin Popescu 已提交
408

C
Cosmin Popescu 已提交
409 410
The `g:sw_shortcuts_sql_buffer_statement` variable is used for the sql buffer
itself, while the `g:sw_shortcuts_sql_results` variable is used for the result
C
Cosmin Popescu 已提交
411 412 413
set buffer (see the 4th scren shot).

As soon as a SQL buffer is opened the shortcuts from the
C
Cosmin Popescu 已提交
414 415
`g:sw_shortcuts_sql_buffer_statement` will be mapped. If the variable is not
set, then the `resources/shortcuts_sql_buffer_statement.vim` file is loaded.
C
Cosmin Popescu 已提交
416
So, have a look at this file for further details. Please note that for
C
Cosmin Popescu 已提交
417
executing the current SQL, the default shortcut is .
C
Cosmin Popescu 已提交
418 419

The same goes for a result set buffer. The shortcuts from the file pointed by
C
Cosmin Popescu 已提交
420 421
the `g:sw_shortcuts_sql_results` variable are loaded. If the variable is not
set, then the shortcuts from `resources/shortcuts_sql_results.vim` are loaded.
C
Cosmin Popescu 已提交
422 423
If you want further details, please have a look at this file.

C
Cosmin Popescu 已提交
424 425
You can also have comment in the format  on a single
line. This comments will be parsed by the plugin. If the command begins with a
C
Cosmin Popescu 已提交
426
`:` it will be interpreted as a `vim` command and executed by vim. Otherwise,
C
Cosmin Popescu 已提交
427
the command will be sent to the DBMS when opening the file.
C
Cosmin Popescu 已提交
428 429 430

Examples:

C
Cosmin Popescu 已提交
431

C
Cosmin Popescu 已提交
432 433 434 435

This command will be sent to the DBMS and will start a new transaction every
time when you open this buffer.

C
Cosmin Popescu 已提交
436
--------------------------------------------------------------------------------
C
Cosmin Popescu 已提交
437
EXECUTE THE CURRENT STATEMENT    *vim-sql-workbench-execute_the_current_statement*
C
Cosmin Popescu 已提交
438

C
Cosmin Popescu 已提交
439
As stated already, you can press  in normal mode or
C
Cosmin Popescu 已提交
440
you can have your own shortcut. Alternatively, in normal mode, you can execute
C
Cosmin Popescu 已提交
441
`SWSqlExecuteCurrent` command.
C
Cosmin Popescu 已提交
442

C
Cosmin Popescu 已提交
443 444 445
The statement between the last 2 delimiters will be sent to the server, or
from the beginning of the file until the first delimiter, or from the last
delimiter to the end of the file, depending on where your cursor is placed.
C
Cosmin Popescu 已提交
446

C
Cosmin Popescu 已提交
447
--------------------------------------------------------------------------------
C
Cosmin Popescu 已提交
448
EXECUTE THE SELECTED STATEMENT  *vim-sql-workbench-execute_the_selected_statement*
C
Cosmin Popescu 已提交
449

C
Cosmin Popescu 已提交
450
In visual mode, you can press  or your own custom shortcut.
C
Cosmin Popescu 已提交
451
Alternatively, you can execute the `SWSqlExecuteSelected` command. Please be
C
Cosmin Popescu 已提交
452 453
careful to delete the range before, if you want to execute the command from
the visual mode.
C
Cosmin Popescu 已提交
454 455 456

The selected text is going to be sent to the DBMS.

C
Cosmin Popescu 已提交
457
--------------------------------------------------------------------------------
C
Cosmin Popescu 已提交
458
EXECUTE ALL STATEMENTS                  *vim-sql-workbench-execute_all_statements*
C
Cosmin Popescu 已提交
459

C
Cosmin Popescu 已提交
460
In visual mode, you can press  or your own custom shortcut.
C
Cosmin Popescu 已提交
461
Alternatively, you can execute the `SWSqlExecuteAll` command. All the buffer
C
Cosmin Popescu 已提交
462
is going to be sent to the DBMS.
C
Cosmin Popescu 已提交
463

C
Cosmin Popescu 已提交
464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514
--------------------------------------------------------------------------------
EVENTS                                                  *vim-sql-workbench-events*

The following events exist in the plugin:

*   `new_instance` (triggered when a new instance of  is
    spawned).
*   `profile_changed` (triggered every time a connection to a new profile is
    detected)

In order to attach a hook to an event, you have to call `sw#server#add_event`
with 2 arguments: the event name and the event listener. For an example, check
the `plugin/sw.vim` file in the source code.

--------------------------------------------------------------------------------
SCHEMA REPORT                                    *vim-sql-workbench-schema_report*

 has the ability to generate a very usefull schema report.
This report is used by the autocomplete intellisense and by references tree.
If you want to have intellisense for a profile, in the GUI of  profiles page, add the extended property `report` with the value
`true` (see
here (http://www.sql-workbench.net/manual/profiles.html#profile-extended-properties)).
The report is going to be generated using a paralel background connection.
This means that the current connection will not have to suffer if the report
generation will take too long (depending on your database size, this can even
take several minutes).

It is very usefull to have this report. Other than intellisense, you can also
see in the db explorer the dependencies tree ( and `References`
options).

Please note that the intellisense and the references tree will not work
without this report.

If you have schemas with the same structure from one profile to another you
don't have to generate the report for all the profiles. You can generate it
from one profile (usually `dev` or `test`) and for the rest of the profiles
you can set the extended property `use-report` with the value of the other
profile name, including the group.

So, for example, if you have the profiles `dev` in the group `LOCAL` and
`prod`, which are basically identically, you might not want to run the schema
report on prod. So, you set the extended property `report` with the value
`true` for the `dev` profile and the extended property `use-report` with the
value `LOCAL\dev`. Like this, every time when you connect to the `dev`
profile, a new connection will be spawned in the background which will
generate the schema report. Once this is generated at least once, you have
intellisense and references tree available. And every time you connect to the
`prod` profile, you always have the same intellisense autocomplete and the
references tree.

C
Cosmin Popescu 已提交
515
--------------------------------------------------------------------------------
C
Cosmin Popescu 已提交
516
INTELLISENSE                                      *vim-sql-workbench-intellisense*
C
Cosmin Popescu 已提交
517

C
Cosmin Popescu 已提交
518
`vim-sqlworkbench` plugin comes with intellisense out of the box. In order to
C
Cosmin Popescu 已提交
519 520 521 522 523
take advantage of the auto complete intellisense, you have to set the schema
report (see the previous section).

If the schema report is available (either by setting the `report` option or by
setting the `use-report` option) you can press &lt;C-x&gt;&lt;C-u&gt; in insert
C
Cosmin Popescu 已提交
524
mode in a sql statement.
C
Cosmin Popescu 已提交
525

C
Cosmin Popescu 已提交
526
Note: due to constant conflicts with dbext plugin (which apparently has some
C
Cosmin Popescu 已提交
527
parts included in the `/usr/share/vim` folder) I prefer to switch to
C
Cosmin Popescu 已提交
528
&lt;C-x&gt;&lt;C-u&gt;. So, you cannot use &lt;C-x&gt;&lt;C-o&gt; anymore for
C
Cosmin Popescu 已提交
529
intellisense
C
Cosmin Popescu 已提交
530 531

The plugin will try to determine where you are in the sql and return the
C
Cosmin Popescu 已提交
532
appropriate options. For example, if you are in the fields part of a `select`
C
Cosmin Popescu 已提交
533
statement, the options returned will be the fields based on the tables from
C
Cosmin Popescu 已提交
534
the `from` part of the `select`. If you are in the `from` part, then the list
C
Cosmin Popescu 已提交
535 536 537
of tables is returned. If you have an identifier followed by a dot, then if
that identifier is a table, a view or an alias of a view or subquery, the
system will return the corresponding list of fields.
C
Cosmin Popescu 已提交
538 539 540 541 542 543

Also the subqueries are parsed and the appropriate fields are returned.

If you are in a subquery in a bigger query, the auto complete will be executed
at the level of the subquery.

C
Cosmin Popescu 已提交
544 545
If you are in a `union` `select` statement, the system will try to determine
in which `select` the cursor is placed and execute auto completion for that sql.
C
Cosmin Popescu 已提交
546

C
Cosmin Popescu 已提交
547
NOTE: The autocomplete feature is implemented using regular expressions.
C
Cosmin Popescu 已提交
548 549 550 551
Because of using regular expressions, it's possible that I've missed cases. If
you notice any case where the autocomplete is not working properly, please let
me know.

C
Cosmin Popescu 已提交
552
--------------------------------------------------------------------------------
C
Cosmin Popescu 已提交
553
GET AN OBJECT DEFINITION              *vim-sql-workbench-get_an_object_definition*
C
Cosmin Popescu 已提交
554

C
Cosmin Popescu 已提交
555
When with the cursor on top of any word in the buffer or in the result set,
C
Cosmin Popescu 已提交
556
you can click `<leader>oi` or your own custom shortcut. This will display that
C
Cosmin Popescu 已提交
557 558
object definition if the object exists in the result set buffer or an error
message.
C
Cosmin Popescu 已提交
559

C
Cosmin Popescu 已提交
560
Alternatively you can execute the `SWSqlObjectInfo` command from normal mode.
C
Cosmin Popescu 已提交
561

C
Cosmin Popescu 已提交
562
Basically the command  is sent to the DBMS and the output
C
Cosmin Popescu 已提交
563 564
returned.

C
Cosmin Popescu 已提交
565
--------------------------------------------------------------------------------
C
Cosmin Popescu 已提交
566
GET AN OBJECT SOURCE                      *vim-sql-workbench-get_an_object_source*
C
Cosmin Popescu 已提交
567 568

When you are with the cursor on top of any word in the buffer or in the result
C
Cosmin Popescu 已提交
569
set, you can click `<leader>os` or your own custom shortcut. This will display
C
Cosmin Popescu 已提交
570
the object source if the object exists in the result set buffer or an error
C
Cosmin Popescu 已提交
571 572
message.

C
Cosmin Popescu 已提交
573
Alternatively, you can execute the `SWSqlObjectSource` command from normal
C
Cosmin Popescu 已提交
574 575
mode.

C
Cosmin Popescu 已提交
576
--------------------------------------------------------------------------------
C
Cosmin Popescu 已提交
577
MAXIMUM NUMBER OF ROWS.                *vim-sql-workbench-maximum_number_of_rows.*
C
Cosmin Popescu 已提交
578

C
Cosmin Popescu 已提交
579 580 581
By default, the maximum number of results returned by a select is 5000. You
can change this with the  command. See
here (http://www.sql-workbench.net/manual/wb-commands.html#command-set)
C
Cosmin Popescu 已提交
582

C
Cosmin Popescu 已提交
583
--------------------------------------------------------------------------------
C
Cosmin Popescu 已提交
584
CHANGING RESULT SETS DISPLAY MODE *vim-sql-workbench-changing_result_sets_display_mode*
C
Cosmin Popescu 已提交
585

C
Cosmin Popescu 已提交
586
In the result set buffer, you can click `<leader>d` or your own custom shortcut
C
Cosmin Popescu 已提交
587 588 589 590
on top of a row. This will toggle the row display to have each column on a row
for the selected row. To change back the display mode, click again the same
shortcut.

C
Cosmin Popescu 已提交
591
Alternatively, you can execute the `WbDisplay` command. See
C
Cosmin Popescu 已提交
592
here (http://www.sql-workbench.net/manual/console-mode.html) for more detail.
C
Cosmin Popescu 已提交
593

C
Cosmin Popescu 已提交
594
--------------------------------------------------------------------------------
C
Cosmin Popescu 已提交
595
FILTERING THE RESULTSET                *vim-sql-workbench-filtering_the_resultset*
C
Cosmin Popescu 已提交
596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613

While in the result window, you can filter the displayed rows. With the cursor
on a resultset, you can just call the `SWSqlFilterColumn` command with the
name of the column as a parameter (you can also click `tab` after the command,
a list of available columns will be displayed). After this you will be asked
to insert a filter value.

The filter value can be a regular expression pattern or an arithmetic value
(this begins with `>`, `<` or `==`)

Note: The filtering is done row by row. This means that if you have a
multirow column, the filtering will be done based on each row of that column
and not by the full value.

Note2: If you want to filter for a mathematical value for equality, you have
to insert two equal signs (`==`). For example: .

--------------------------------------------------------------------------------
C
Cosmin Popescu 已提交
614
HIDING COLUMNS                                  *vim-sql-workbench-hiding_columns*
C
Cosmin Popescu 已提交
615 616 617 618 619 620 621 622 623

While in a result window, you can hide columns from a result set.

With the cursor on a resultset, you can call the `SWSqlHideColumn` command.
The command takes as an argument the name of the column to hide (there is also
an autocomplete with the available columns).

Example: 

C
Cosmin Popescu 已提交
624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657
--------------------------------------------------------------------------------
CTRLP INTEGRATION                            *vim-sql-workbench-ctrlp_integration*

 provides integration with the `CtrlP` plugin. In order to
activate it, you need to set the `g:sw_config_dir` option to point to your
 configuration directory. Then, in your `.vimrc` file, you
need to activate the `CtrlP` extension `sw_profiles`, by setting the
`g:ctrlp_extensions` variable.

By activating the integration, you can change a buffer connection with
`CtrlP`. You activate `CtrlP` and then select the  tab
and select your profile. If the buffer is already connected to an  instance, then the current connection will be changed. If no,
then the buffer will get connected to an  instance and also
open a connection to the selected profile.

--------------------------------------------------------------------------------
AIRLINE INTEGRATION                        *vim-sql-workbench-airline_integration*

 also provides integration with [](https://github.com/vim-airline/vim-airline) plugin. Since I haven't
really found out how to create an extension and place it in any folder, you
will have to manually copy the `resources/airline/sw.vim` file into the
`Airline` extensions folder. Then you need to enable the extension in your
`.vimrc` file by setting the `g:airline_extensions` variable to include the
`sw` extension.

Once you activate the integration, every time when you connect a buffer to an
 instance, you will see the in the status bar the current
url (next to the file name). If the buffer is connected to ,
but is not connected to a DBMS, then you will see the  string.

Alternatively, if you don't use Airline integration, you can still see the
current url in the status line by activating the status line in vim () and then you can set the status line to include the buffer
url. For example: .

C
Cosmin Popescu 已提交
658
================================================================================
C
Cosmin Popescu 已提交
659
SQL COMMANDS                                      *vim-sql-workbench-sql_commands*
C
Cosmin Popescu 已提交
660 661

You can send a sql query to the DBMS from the vim command line using the
C
Cosmin Popescu 已提交
662
command `SWSqlExecuteNow`. The parameters are the sql query. Please note that
C
Cosmin Popescu 已提交
663
by default no results will be shown. If you want to see all that happened on
C
Cosmin Popescu 已提交
664
the server side, use the `SWSqlExecuteNowLastResult` command. This will show
C
Cosmin Popescu 已提交
665 666 667
you what happened with the last command sent from the vim command line.

This is useful if you want to put vim shortcuts for simple things. Like, for
C
Cosmin Popescu 已提交
668
example, you could have in your `vimrc`:
C
Cosmin Popescu 已提交
669
>
C
Cosmin Popescu 已提交
670
    nnoremap <leader>t :SWSqlExecuteNow wbdisplay tab;<cr>
C
Cosmin Popescu 已提交
671
<
C
Cosmin Popescu 已提交
672

C
Cosmin Popescu 已提交
673
Then pressing `<leader>t` in normal mode, would set the display to tab for the
C
Cosmin Popescu 已提交
674
current buffer.
C
Cosmin Popescu 已提交
675

C
Cosmin Popescu 已提交
676 677
Note: This command will not be recorded in `g:sw_last_sql_query`. The
delimiter is the `;`.
C
Cosmin Popescu 已提交
678

C
Cosmin Popescu 已提交
679
================================================================================
C
Cosmin Popescu 已提交
680
SEARCHING                                            *vim-sql-workbench-searching*
C
Cosmin Popescu 已提交
681

C
Cosmin Popescu 已提交
682
 comes with two very handy and powerful commands:
C
Cosmin Popescu 已提交
683
`WbGrepSource` and `WbGrepData`. `vim-sqlworkbench` takes advantage of both of
C
Cosmin Popescu 已提交
684 685 686
them and implements searching options. You can search in objects source code,
or you can search tables data.

C
Cosmin Popescu 已提交
687
--------------------------------------------------------------------------------
C
Cosmin Popescu 已提交
688
SEARCHING IN OBJECTS SOURCE CODE *vim-sql-workbench-searching_in_objects_source_code*
C
Cosmin Popescu 已提交
689

C
Cosmin Popescu 已提交
690
Of course, you can always execute `WbGrepSource` in a sql buffer and send it to
C
Cosmin Popescu 已提交
691 692
the DBMS. For a full documentation of the command, please see
here (http://www.sql-workbench.net/manual/wb-commands.html#command-search-source).
C
Cosmin Popescu 已提交
693

C
Cosmin Popescu 已提交
694 695 696
Alternatively, you can call one of the three `vim-sqlworkbench` search
commands available: `SWSearchObject`, `SWSearchObjectAdvanced` or
`SWSearchObjectDefaults`.
C
Cosmin Popescu 已提交
697

C
Cosmin Popescu 已提交
698
The `SWSearchObject` command will take one argument, which is the search
C
Cosmin Popescu 已提交
699
string. The command which will be sent to the DBMS is . This means that you execute a search with
C
Cosmin Popescu 已提交
700 701
default values. For a list of these, see the above link.

C
Cosmin Popescu 已提交
702
Example: 
C
Cosmin Popescu 已提交
703

C
Cosmin Popescu 已提交
704
The `SWSearchObjectAdvanced` command will open an interactive command prompt
C
Cosmin Popescu 已提交
705 706
asking for every parameter value, beginning with the search terms.

C
Cosmin Popescu 已提交
707 708 709
The `SWSearchObjectDefaults` command takes one argument (the search terms) and
will perform a search using all the defaults defined in `vim-sqlworkbench`
plugin. These defaults can be changed in `vimrc`.
C
Cosmin Popescu 已提交
710

C
Cosmin Popescu 已提交
711
Example: 
C
Cosmin Popescu 已提交
712

C
Cosmin Popescu 已提交
713
--------------------------------------------------------------------------------
C
Cosmin Popescu 已提交
714
SEARCHING FOR DATA INSIDE TABLES *vim-sql-workbench-searching_for_data_inside_tables*
C
Cosmin Popescu 已提交
715

C
Cosmin Popescu 已提交
716
You can execute `WbGrepData` in a sql buffer and send it to the DBMS. For a
C
Cosmin Popescu 已提交
717 718
full documentation of the command, please see
here (http://www.sql-workbench.net/manual/wb-commands.html#command-search-data).
C
Cosmin Popescu 已提交
719

C
Cosmin Popescu 已提交
720 721 722
Alternatively, you can call one of the three `vim-sqlworkbench` search
commands available: `SWSearchData`, `SWSearchDataAdvanced` or
`SWSearchDataDefaults`.
C
Cosmin Popescu 已提交
723

C
Cosmin Popescu 已提交
724
All the three commands work as their counter parts for searching object.
C
Cosmin Popescu 已提交
725 726 727

If you are in an sql buffer, then the results are displayed in the result sets
buffer. If you are in a database explorer, then the search results are
C
Cosmin Popescu 已提交
728
displayed in the bottom left panel.
C
Cosmin Popescu 已提交
729

C
Cosmin Popescu 已提交
730
================================================================================
C
Cosmin Popescu 已提交
731
EXPORTING                                            *vim-sql-workbench-exporting*
C
Cosmin Popescu 已提交
732

C
Cosmin Popescu 已提交
733 734
`vim-sqlworkbench` takes advantage of the very powerful
command, `WbExport`.
C
Cosmin Popescu 已提交
735

C
Cosmin Popescu 已提交
736 737
As usual, you can always execute the `WbExport` command inside a sql buffer.
To see the full documentation of the `WbExport` command, have a look
C
Cosmin Popescu 已提交
738
here (http://www.sql-workbench.net/manual/command-export.html).
C
Cosmin Popescu 已提交
739

C
Cosmin Popescu 已提交
740
Note: If you use the wbexport command, you need to send both of the queries
C
Cosmin Popescu 已提交
741 742
at once, by selecting both queries (first the `WbExport` query and then the
exported query) and then running `SWSqlExecuteSelected`. This happens because
C
Cosmin Popescu 已提交
743
the plugin will send after each statement a silent command to notice vim that
C
Cosmin Popescu 已提交
744 745
a new result is waiting. So, if you execute `WbExport`, the exported statement
will be the silent one which is void and is not a `select` statement.
C
Cosmin Popescu 已提交
746

C
Cosmin Popescu 已提交
747
Or you can execute the `SWSqlExport` command. This will open an interactive
C
Cosmin Popescu 已提交
748 749 750 751 752
input dialog which will ask for the format and the destination file and will
export the last sql command. If you are in a database explorer, in the right
panel, you can click on "E". This shortcut is not modifiable. This will export
what ever is in the right panel, after asking for the format and the
destination file. Please note that because of extra dependencies required for
C
Cosmin Popescu 已提交
753 754
`xls` export, `vim-sqlworkbench` does not provide support for this format.
However, you can export as `ods`, which is what you should use anyway. See
C
Cosmin Popescu 已提交
755 756
here (http://www.fsf.org/campaigns/opendocument/) or
here (http://www.fsf.org/campaigns/opendocument/download)
C
Cosmin Popescu 已提交
757

C
Cosmin Popescu 已提交
758
================================================================================
C
Cosmin Popescu 已提交
759
VARIABLES                                            *vim-sql-workbench-variables*
C
Cosmin Popescu 已提交
760

C
Cosmin Popescu 已提交
761 762 763
 supports user defined variables (you can have your queries
sent to the database parameterized). See
here (http://www.sql-workbench.net/manual/using-variables.html).
C
Cosmin Popescu 已提交
764

C
Cosmin Popescu 已提交
765 766
By default, in , the variables are enclosed between `$[` and
`]`. These can be
C
Cosmin Popescu 已提交
767
changed (http://www.sql-workbench.net/manual/using-variables.html#access-variable).
C
Cosmin Popescu 已提交
768

C
Cosmin Popescu 已提交
769 770 771 772
You can use `WbVarSet` and `WbVarUnset` in a sql buffer. If you want the
system to ask for a value, then you can use the `$[?` form of a parameter.
Please note that in  there is no difference between `?` and
`&`, since there is no way to get a list of vars in `vimscript` from 
C
Cosmin Popescu 已提交
773

C
Cosmin Popescu 已提交
774
================================================================================
C
Cosmin Popescu 已提交
775
COMMANDS                                              *vim-sql-workbench-commands*
C
Cosmin Popescu 已提交
776

C
Cosmin Popescu 已提交
777
--------------------------------------------------------------------------------
C
Cosmin Popescu 已提交
778
SWDBEXPLORER                                      *vim-sql-workbench-swdbexplorer*
C
Cosmin Popescu 已提交
779

C
Cosmin Popescu 已提交
780
Parameters:
C
Cosmin Popescu 已提交
781

C
Cosmin Popescu 已提交
782 783
*   profile name: the name of the profile for which to open the database explorer.
*   port: the port on which the server listens
C
Cosmin Popescu 已提交
784 785 786 787

Opens a database explorer for the desired profile using the server from the
specified port.

C
Cosmin Popescu 已提交
788
NOTE: If you set the
C
Cosmin Popescu 已提交
789
`g:sw_config_dir` variable to point to the  settings folder,
C
Cosmin Popescu 已提交
790 791
the command will autocomplete the profile names. See
here (http://www.sql-workbench.net/manual/install.html#config-dir)
C
Cosmin Popescu 已提交
792

C
Cosmin Popescu 已提交
793
--------------------------------------------------------------------------------
C
Cosmin Popescu 已提交
794
SWDBEXPLORERCLOSE                            *vim-sql-workbench-swdbexplorerclose*
C
Cosmin Popescu 已提交
795

C
Cosmin Popescu 已提交
796
Parameters;
C
Cosmin Popescu 已提交
797

C
Cosmin Popescu 已提交
798 799
*   profile name (optional): the name of the database explorer that should be
    closed.
C
Cosmin Popescu 已提交
800 801 802 803 804 805 806 807

Closes a database explorer. If no profile name is specified, if you are inside
a database explorer, then that database explorer is closed. Otherwise, the
system will generate an error.

If you specify a profile name, then the database explorer which is opened for
the indicated profile is closed.

C
Cosmin Popescu 已提交
808
--------------------------------------------------------------------------------
C
Cosmin Popescu 已提交
809
SWSQLEXECUTECURRENT                        *vim-sql-workbench-swsqlexecutecurrent*
C
Cosmin Popescu 已提交
810 811 812 813 814

In an sql buffer executes the current statement. You can execute this command
in normal or insert mode. This is the statement between two consecutive
identifiers, or from the beginning of the file to the first identifier or from
the last identifier to the end of the file. You can change the delimiter using
C
Cosmin Popescu 已提交
815
the `SWSqlDelimiter` command.
C
Cosmin Popescu 已提交
816

C
Cosmin Popescu 已提交
817
--------------------------------------------------------------------------------
C
Cosmin Popescu 已提交
818
SWSQLEXECUTESELECTED                      *vim-sql-workbench-swsqlexecuteselected*
C
Cosmin Popescu 已提交
819

C
Cosmin Popescu 已提交
820 821
In an sql buffer, executes the current selected statement. The command works
in visual mode. Be careful to delete the range before typing the command.
C
Cosmin Popescu 已提交
822

C
Cosmin Popescu 已提交
823
--------------------------------------------------------------------------------
C
Cosmin Popescu 已提交
824
SWSQLEXECUTEALL                                *vim-sql-workbench-swsqlexecuteall*
C
Cosmin Popescu 已提交
825 826 827

Send all sql statements from the buffer to the DBMS.

C
Cosmin Popescu 已提交
828
--------------------------------------------------------------------------------
C
Cosmin Popescu 已提交
829
SWSQLTOGGLEMESSAGES                        *vim-sql-workbench-swsqltogglemessages*
C
Cosmin Popescu 已提交
830 831

If you have a result set displayed in the result set buffer, you can toggle
C
Cosmin Popescu 已提交
832 833 834
between the result displayed and the messages produced by the command with
this command. The command works from the sql buffer and from the result set
buffer.
C
Cosmin Popescu 已提交
835

C
Cosmin Popescu 已提交
836
--------------------------------------------------------------------------------
C
Cosmin Popescu 已提交
837
SWSQLOBJECTINFO                                *vim-sql-workbench-swsqlobjectinfo*
C
Cosmin Popescu 已提交
838 839

In a sql buffer or in a result set buffer, you can position the cursor on top
C
Cosmin Popescu 已提交
840 841
of any word and call this command. The plugin will send to the DBMS . If the word that you selected is a valid database object, you will
see its definition. Otherwise it will return an error.
C
Cosmin Popescu 已提交
842

C
Cosmin Popescu 已提交
843
--------------------------------------------------------------------------------
C
Cosmin Popescu 已提交
844
SWSQLOBJECTSOURCE                            *vim-sql-workbench-swsqlobjectsource*
C
Cosmin Popescu 已提交
845 846 847 848 849 850

Like the previous command, if you are with your cursor on top of a word and
call this command, the plugin will return it's source code, if the selected
word is an object in the database. Otherwise, it will return an empty result
set.

C
Cosmin Popescu 已提交
851
--------------------------------------------------------------------------------
C
Cosmin Popescu 已提交
852
SWSQLEXECUTENOW                                *vim-sql-workbench-swsqlexecutenow*
C
Cosmin Popescu 已提交
853

C
Cosmin Popescu 已提交
854
Parameters:
C
Cosmin Popescu 已提交
855

C
Cosmin Popescu 已提交
856 857
*   port: the port on which to execute the command
*   sql: The query to be sent to the DBMS
C
Cosmin Popescu 已提交
858 859 860

Executes a query against the DBMS on the indicated port.

C
Cosmin Popescu 已提交
861
--------------------------------------------------------------------------------
C
Cosmin Popescu 已提交
862
SWSQLEXECUTENOWLASTRESULT            *vim-sql-workbench-swsqlexecutenowlastresult*
C
Cosmin Popescu 已提交
863

C
Cosmin Popescu 已提交
864
Shows the communication with the server for the last `SWSqlExecuteNow` command.
C
Cosmin Popescu 已提交
865

C
Cosmin Popescu 已提交
866
--------------------------------------------------------------------------------
C
Cosmin Popescu 已提交
867
SWSQLEXPORT                                        *vim-sql-workbench-swsqlexport*
C
Cosmin Popescu 已提交
868 869

This command will export the last executed statement. Of course, if your last
C
Cosmin Popescu 已提交
870 871
statement did not produced any results, you will have an empty file. The
plugin will ask you about the format and about the output file. You can export
C
Cosmin Popescu 已提交
872 873
in one of the following formats: `text`, `sqlinsert`, `sqlupdate`,
`sqldeleteinsert`, `xml`, `ods`, `html`, `json`.
C
Cosmin Popescu 已提交
874

C
Cosmin Popescu 已提交
875
--------------------------------------------------------------------------------
C
Cosmin Popescu 已提交
876
SWSEARCHOBJECT                                  *vim-sql-workbench-swsearchobject*
C
Cosmin Popescu 已提交
877

C
Cosmin Popescu 已提交
878
Parameters:
C
Cosmin Popescu 已提交
879

C
Cosmin Popescu 已提交
880
*   search terms: the terms that you are searching.
C
Cosmin Popescu 已提交
881 882

This command performs a search in the source code of the database objects. It
C
Cosmin Popescu 已提交
883
uses the defaults of . The command which is used is
C
Cosmin Popescu 已提交
884
`WbGrepSource`. You can see more details about the parameters and their
C
Cosmin Popescu 已提交
885 886
default values
here (http://www.sql-workbench.net/manual/wb-commands.html#command-search-source).
C
Cosmin Popescu 已提交
887

C
Cosmin Popescu 已提交
888
--------------------------------------------------------------------------------
C
Cosmin Popescu 已提交
889
SWSEARCHOBJECTADVANCED                  *vim-sql-workbench-swsearchobjectadvanced*
C
Cosmin Popescu 已提交
890 891 892 893 894 895 896

This command will perform an advanced search. It will ask for each possible
parameter. You can cancel the search at any time by replying with an empty
value. This, however, is not possible for the columns input, since the empty
string in the columns means that you want all the columns but only the first
row of each.

C
Cosmin Popescu 已提交
897
--------------------------------------------------------------------------------
C
Cosmin Popescu 已提交
898
SWSEARCHOBJECTDEFAULTS                  *vim-sql-workbench-swsearchobjectdefaults*
C
Cosmin Popescu 已提交
899

C
Cosmin Popescu 已提交
900
Parameters:
C
Cosmin Popescu 已提交
901

C
Cosmin Popescu 已提交
902
*   search terms: the terms that you are searching.
C
Cosmin Popescu 已提交
903 904 905 906

This command will perform a search using as default values for all the
parameters the values defined through the vim variables:

C
Cosmin Popescu 已提交
907 908 909 910 911
*   `g:sw_search_default_regex`
*   `g:sw_search_default_match_all`
*   `g:sw_search_default_ignore_case`
*   `g:sw_search_default_types`
*   `g:sw_search_default_compare_types`
C
Cosmin Popescu 已提交
912

C
Cosmin Popescu 已提交
913
--------------------------------------------------------------------------------
C
Cosmin Popescu 已提交
914
SWSEARCHDATA                                      *vim-sql-workbench-swsearchdata*
C
Cosmin Popescu 已提交
915

C
Cosmin Popescu 已提交
916
Parameters:
C
Cosmin Popescu 已提交
917

C
Cosmin Popescu 已提交
918
*   search terms: the terms that you are searching.
C
Cosmin Popescu 已提交
919 920

This command performs a search in the data in the tables. It uses the defaults
C
Cosmin Popescu 已提交
921
of . The command which is used is `WbGrepData`. You can see
C
Cosmin Popescu 已提交
922 923
more details about the parameters and their default values
here (http://www.sql-workbench.net/manual/wb-commands.html#command-search-data).
C
Cosmin Popescu 已提交
924

C
Cosmin Popescu 已提交
925
--------------------------------------------------------------------------------
C
Cosmin Popescu 已提交
926
SWSEARCHDATAADVANCED                      *vim-sql-workbench-swsearchdataadvanced*
C
Cosmin Popescu 已提交
927 928 929

This command will perform an advanced search in the tables data. It will ask
for each possible parameter. You can cancel the search at any time by replying
C
Cosmin Popescu 已提交
930
with an empty value, with the exception of the `excludeTables` parameter,
C
Cosmin Popescu 已提交
931 932
since an empty value here means that you want to search in all the tables and
is not an unusual request.
C
Cosmin Popescu 已提交
933

C
Cosmin Popescu 已提交
934
--------------------------------------------------------------------------------
C
Cosmin Popescu 已提交
935
SWSEARCHDATADEFAULTS                      *vim-sql-workbench-swsearchdatadefaults*
C
Cosmin Popescu 已提交
936

C
Cosmin Popescu 已提交
937
Parameters:
C
Cosmin Popescu 已提交
938

C
Cosmin Popescu 已提交
939
*   search terms: the terms that you are searching.
C
Cosmin Popescu 已提交
940 941 942 943

This command will perform a search in tables data using as default values for
all the parameters the values defined through the vim variables:

C
Cosmin Popescu 已提交
944 945 946 947 948 949
*   `g:sw_search_default_ignore_case`
*   `g:sw_search_default_compare_types`
*   `g:sw_search_default_tables`
*   `g:sw_search_default_data_types`
*   `g:sw_search_default_exclude_tables`
*   `g:sw_search_default_exclude_lobs`
C
Cosmin Popescu 已提交
950

C
Cosmin Popescu 已提交
951
--------------------------------------------------------------------------------
C
Cosmin Popescu 已提交
952
SWDBEXPLORERTOGGLEFORMDISPLAY    *vim-sql-workbench-swdbexplorertoggleformdisplay*
C
Cosmin Popescu 已提交
953 954 955 956 957 958

If on a line in the results panel which contains a row in a resultset, then
this row will be displayed as a form. If already displaying a form, then the
resultset will be displayed.

--------------------------------------------------------------------------------
C
Cosmin Popescu 已提交
959
SWSQLSHOWALLCOLUMNS                        *vim-sql-workbench-swsqlshowallcolumns*
C
Cosmin Popescu 已提交
960 961 962 963

This will unhide all hidden columns from the current result set

--------------------------------------------------------------------------------
C
Cosmin Popescu 已提交
964 965 966 967 968 969 970 971 972 973 974 975 976
SWSQLWIPEOUTRESULTSSETS                *vim-sql-workbench-swsqlwipeoutresultssets*

This will wipeout the list of the resultsets. If you execute multiple sql
statements, the results are stored in the resultsets buffer. When you close
it, and then execute another sql statement, you will notice that the latest
result sets are still there. If you don't want this, you can call this
command. Next time you execute an sql statement, the resultsets will be empty.

If you want to wipeout all the resultsets for all buffers, you have to execute
the command followed by a `!` (`SWSqlWipeoutResultsSets!`).

--------------------------------------------------------------------------------
SWSQLSHOWONLYCOLUMN                        *vim-sql-workbench-swsqlshowonlycolumn*
C
Cosmin Popescu 已提交
977 978 979 980 981 982 983 984 985 986 987

Parameters:

*   column name: the name of the column to show

This will hide all the columns from the current resultset with the exception
of the mentioned column.

Note: there is an autocomplete for the column name

--------------------------------------------------------------------------------
C
Cosmin Popescu 已提交
988
SWSQLSHOWONLYCOLUMNS                      *vim-sql-workbench-swsqlshowonlycolumns*
C
Cosmin Popescu 已提交
989 990 991 992 993 994 995 996 997

*   column names: a list of white space separated list of columns to be shown

This will hide all the columns from the current resultset with the exception
of the mentioned columns

Note: there is an autocomplete for the column names

--------------------------------------------------------------------------------
C
Cosmin Popescu 已提交
998
SWSQLSHOWCOLUMN                                *vim-sql-workbench-swsqlshowcolumn*
C
Cosmin Popescu 已提交
999 1000 1001 1002 1003 1004 1005 1006 1007 1008

Parameters:

*   column name: the name of the column to show

This will show the indicated column name (assuming that it is hidden)

Note: there is an autocomplete for the column name

--------------------------------------------------------------------------------
C
Cosmin Popescu 已提交
1009
SWSQLHIDECOLUMN                                *vim-sql-workbench-swsqlhidecolumn*
C
Cosmin Popescu 已提交
1010 1011 1012 1013 1014 1015 1016 1017 1018 1019

Parameters:

*   column name: the name of the column to hide

This will hide the indeicated column.

Note: there is an autocomplete for the column name

--------------------------------------------------------------------------------
C
Cosmin Popescu 已提交
1020
SWSQLFILTERCOLUMN                            *vim-sql-workbench-swsqlfiltercolumn*
C
Cosmin Popescu 已提交
1021 1022 1023 1024 1025

Parameters:

*   column name: the name of the column to filter

C
Cosmin Popescu 已提交
1026 1027 1028 1029
This will apply a filter on the specified column. The filter can be either a
mathematical expression (like ) if the column is an `integer` or `float`
column. If the column is of type `string`, you can have as a filter a regular
expression. For example, .
C
Cosmin Popescu 已提交
1030 1031 1032 1033

Note: there is an autocomplete for the column name

--------------------------------------------------------------------------------
C
Cosmin Popescu 已提交
1034
SWSQLUNFILTERCOLUMN                        *vim-sql-workbench-swsqlunfiltercolumn*
C
Cosmin Popescu 已提交
1035 1036 1037 1038 1039 1040 1041 1042 1043 1044

Parameters:

*   column name: the name of the column to unfilter

This will remove any filters applied on the specified column.

Note: there is an autocomplete for the column name

--------------------------------------------------------------------------------
C
Cosmin Popescu 已提交
1045
SWSQLREMOVEALLFILTERS                    *vim-sql-workbench-swsqlremoveallfilters*
C
Cosmin Popescu 已提交
1046 1047

This will remove all filters applied for the current resultset.
C
Cosmin Popescu 已提交
1048

C
Cosmin Popescu 已提交
1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101
#SWSqlBufferConnect

Parameters:

*   buffer name: the name of the buffer to open and connect to an  instance (optional)

This command will open the selected buffer and connect it to an  instance. If the parameter is missing, then the current buffer
will be connected to an  instance.

Note: when you close the buffer, the  instance process will
also be killed. If you want to close it gracefully, you can use
`SWSqlBufferDisconnect` command, which will send an `exit` to the .

--------------------------------------------------------------------------------
SWSQLBUFFERDISCONNECT                    *vim-sql-workbench-swsqlbufferdisconnect*

This command will disconnect the current buffer from the  and
close the `sqlwbconsole` process.

--------------------------------------------------------------------------------
SWSQLGETSQLCOUNT                              *vim-sql-workbench-swsqlgetsqlcount*

In a connected sql buffer, if you call this command, a query will be sent to
the DBMS fetching the number of rows of the current sql. For example, if your
cursor is on the ; and you call this command, then
the query sent to the DBMS is 

--------------------------------------------------------------------------------
SWSQLGETOBJROWS                                *vim-sql-workbench-swsqlgetobjrows*

In a connected sql buffer, if you call this command, a query will be sent to
the DBMS to fetch the number of rows of the currently selected object. For
example, if your cursor is on top of the `my_table` identifier and you call
this command, the query sent to the DBMS is .

--------------------------------------------------------------------------------
SWSQLSHOWACTIVECONNECTIONS          *vim-sql-workbench-swsqlshowactiveconnections*

This command will display a list of all the active connected buffers to a  instance with their connection strings.

--------------------------------------------------------------------------------
SWSQLSHOLOG                                        *vim-sql-workbench-swsqlsholog*

This command will open the log of the sql queries sent to the DBMS. If the
`g:sw_log_to_file` is set to true, then the name of the file in which the log
is performed is returned. Otherwise you will see the log.

--------------------------------------------------------------------------------
SWSQLSHOWLASTRESULTSET                  *vim-sql-workbench-swsqlshowlastresultset*

This command will re-open the resultsets window without sending a new command
to the DBMS.

C
Cosmin Popescu 已提交
1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113
--------------------------------------------------------------------------------
SWSQLDELETERESULTSET                      *vim-sql-workbench-swsqldeleteresultset*

This command will delete the currently selected resultset from the resultsets
window.

--------------------------------------------------------------------------------
SWSQLREFRESHRESULTSET                    *vim-sql-workbench-swsqlrefreshresultset*

This command will refresh the currently selected resultset from the resultsets
window.

C
Cosmin Popescu 已提交
1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127
--------------------------------------------------------------------------------
SWSQLBUFFERSHARECONNECTION          *vim-sql-workbench-swsqlbuffershareconnection*

This command will share a connection between the current buffer and the one
indicated in the command

--------------------------------------------------------------------------------
SWSQLFOREIGNKEY                                *vim-sql-workbench-swsqlforeignkey*

When in a result set, you can go to a row and call this command with a column
as an argument. A new sql will be generated and you will see the corresponding
column foreign key row. For this to work, the `report` or `use-report` option
has to be active (see the  section)

C
Cosmin Popescu 已提交
1128
================================================================================
C
Cosmin Popescu 已提交
1129
SETTINGS                                              *vim-sql-workbench-settings*
C
Cosmin Popescu 已提交
1130

C
Cosmin Popescu 已提交
1131
--------------------------------------------------------------------------------
C
Cosmin Popescu 已提交
1132
SEARCH OBJECT SOURCE SETTINGS:  *vim-sql-workbench-search_object_source_settings:*
C
Cosmin Popescu 已提交
1133

C
Cosmin Popescu 已提交
1134
*   `g:sw_search_default_regex`: whether to use regular expressions or not when
C
Cosmin Popescu 已提交
1135
    performing a search; default value: "Y"
C
Cosmin Popescu 已提交
1136 1137
*   `g:sw_search_default_match_all`: whether to match or not all the search
    terms or only one (use `OR` or `AND` when performing the search); default
C
Cosmin Popescu 已提交
1138
    value: "Y"
C
Cosmin Popescu 已提交
1139
*   `g:sw_search_default_ignore_case`: whether to ignore the case or not when
C
Cosmin Popescu 已提交
1140
    performing a search; default value: "Y"
C
Cosmin Popescu 已提交
1141
*   `g:sw_search_default_types`: the types of object in which to search; default
C
Cosmin Popescu 已提交
1142
    value: "LOCAL TEMPORARY,TABLE,VIEW,FUNCTION,PROCEDURE,TRIGGER,SYNONYM"
C
Cosmin Popescu 已提交
1143

C
Cosmin Popescu 已提交
1144 1145 1146
Note: this values apply for the `SWSearchObjectDefaults` command. The
`SWSearchObjectAdvanced` will ask for the value of each parameter and
`SWSearchObject` command will use the defaults of .
C
Cosmin Popescu 已提交
1147

C
Cosmin Popescu 已提交
1148
--------------------------------------------------------------------------------
C
Cosmin Popescu 已提交
1149
SEARCH DATA IN TABLES SETTINGS: *vim-sql-workbench-search_data_in_tables_settings:*
C
Cosmin Popescu 已提交
1150

C
Cosmin Popescu 已提交
1151 1152
*   `g:sw_search_default_match_all`: whether to match or not all the search
    terms or only one (use `OR` or `AND` when performing the search); default
C
Cosmin Popescu 已提交
1153
    value: "Y"
C
Cosmin Popescu 已提交
1154
*   `g:sw_search_default_compare_types`: the type of search to be performed (the
C
Cosmin Popescu 已提交
1155
    operator for the search); default value: "contains"
C
Cosmin Popescu 已提交
1156
*   `g:sw_search_default_tables`: the tables to be included in the search;
C
Cosmin Popescu 已提交
1157
    default value: "%", which means all tables
C
Cosmin Popescu 已提交
1158
*   `g:sw_search_default_data_types`: the types of objects in which to perform
C
Cosmin Popescu 已提交
1159
    the search; default value: "TABLE,VIEW"
C
Cosmin Popescu 已提交
1160
*   `g:sw_search_default_exclude_tables`: the list of tables to exclude from
C
Cosmin Popescu 已提交
1161
    search; default value: ""
C
Cosmin Popescu 已提交
1162 1163
*   `g:sw_search_default_exclude_lobs`: whether or not to exclude the `blob` and
    `clob` columns from search; default value: "Y"
C
Cosmin Popescu 已提交
1164

C
Cosmin Popescu 已提交
1165 1166 1167
Note: this values apply for the `SWSearchDataDefaults` command. The
`SWSearchDataAdvanced` will ask for the value of each parameter and
`SWSearchData` command will use the defaults of .
C
Cosmin Popescu 已提交
1168

C
Cosmin Popescu 已提交
1169 1170 1171 1172
To see more about these parameters, see
here (http://www.sql-workbench.net/manual/wb-commands.html#command-search-source)
and
here (http://www.sql-workbench.net/manual/wb-commands.html#command-search-data)
C
Cosmin Popescu 已提交
1173

C
Cosmin Popescu 已提交
1174
--------------------------------------------------------------------------------
C
Cosmin Popescu 已提交
1175
SQL BUFFER SETTINGS:                      *vim-sql-workbench-sql_buffer_settings:*
C
Cosmin Popescu 已提交
1176

C
Cosmin Popescu 已提交
1177
*   `g:sw_sqlopen_command`: the vim command used by `SWSqlBufferConnect`
C
Cosmin Popescu 已提交
1178 1179 1180
    command to open a buffer; possible values: `e|tabnew`; default value: "e",
    which means open with vim `edit` command
*   `g:sw_tab_switches_between_bottom_panels`: if set to true, then clicking tab
C
Cosmin Popescu 已提交
1181
    in a db explorer will switch between the bottom panels
C
Cosmin Popescu 已提交
1182
*   `g:sw_autocomplete_cache_dir`: the location where the autocomplete
C
Cosmin Popescu 已提交
1183
    information is saved. You'll need to set it on Windows to work.
C
Cosmin Popescu 已提交
1184
*   `g:sw_switch_to_results_tab`: If true, then switch to the results buffer
C
Cosmin Popescu 已提交
1185
    after executting a query
C
Cosmin Popescu 已提交
1186
*   `g:sw_highlight_resultsets`: If true, highlight the resultsets headers
C
Cosmin Popescu 已提交
1187 1188 1189 1190 1191 1192
*   `g:sw_command_timer`: If true, then when launching a command, if it takes
    more than one second, you will see a timer in the bottom left of the status
    bar
*   `g:sw_log_to_file`: If true, then the logging of the communication between
    `VIM` and  will be done in a file; otherwise, the logging
    is done in memory
1193 1194
*   `g:sw_sql_name_result_tab`: If enable, rename the result tab using @wbresult;
     default value: 1
C
Cosmin Popescu 已提交
1195

C
Cosmin Popescu 已提交
1196
--------------------------------------------------------------------------------
C
Cosmin Popescu 已提交
1197
DATABASE EXPLORER SETTINGS          *vim-sql-workbench-database_explorer_settings*
C
Cosmin Popescu 已提交
1198

C
Cosmin Popescu 已提交
1199
*   `g:sw_default_right_panel_type`: the file type of the bottom right panel
C
Cosmin Popescu 已提交
1200 1201
    when not specified; default value: "txt"

C
Cosmin Popescu 已提交
1202
--------------------------------------------------------------------------------
C
Cosmin Popescu 已提交
1203
GENERAL SETTINGS:                            *vim-sql-workbench-general_settings:*
C
Cosmin Popescu 已提交
1204

C
Cosmin Popescu 已提交
1205
*   `g:sw_exe`: the location of the  executable; default value:
C
Cosmin Popescu 已提交
1206
    "sqlwbconsole.sh"; you need to set it for the plugin to work
C
Cosmin Popescu 已提交
1207 1208
*   `g:sw_tmp`: the location of your temporary folder; default value: "/tmp"
*   `g:sw_delete_tmp`: if true, then delete the temporary files created to
C
Cosmin Popescu 已提交
1209 1210
    execute any command. Useful for debugging. You can set it to 0 and check all
    the generated files
C
Cosmin Popescu 已提交
1211 1212 1213
*   `g:sw_save_resultsets`: if true, then all the resultsets will be saved,
    event if you close the resultsets window; to clear the resultsets window,
    use `SWSqlWipeoutResultsSets` command.
C
Cosmin Popescu 已提交
1214 1215
*   `g:sw_config_dir`: the config dir of the  (works only with
    build 121.4 and more)
C
Cosmin Popescu 已提交
1216