Home Explore Blog CI



neovim

7th chunk of `runtime/doc/ft_sql.txt`
ed5d4502f62618b9bb6941574c281f0929df71c095268b6b0000000100000fa1
 for example you know
the statement begins with the letter "s".  You can type ahead (without the
quotes) "se" then press:
    <C-Space>t
Assuming "select" is highlighted in the popup list press <Enter> to choose
the entry.  Now type:
    * fr<C-C>a (show all syntax items)
choose "from" from the popup list.

When writing stored procedures using the "type" list is useful.  It contains
a list of all the database supported types.  This may or may not be true
depending on the syntax file you are using.  The SQL Anywhere syntax file
(sqlanywhere.vim) has support for this: >
     BEGIN
	DECLARE customer_id <C-C>T <-- Choose a type from the list


Dynamic features ~

To take advantage of the dynamic features you must first install the
dbext.vim plugin (https://vim.sourceforge.net/script.php?script_id=356).  It
also comes with a tutorial.  From the SQL completion plugin's perspective,
the main feature dbext provides is a connection to a database.  dbext
connection profiles are the most efficient mechanism to define connection
information.  Once connections have been setup, the SQL completion plugin
uses the features of dbext in the background to populate the popups.

What follows assumes dbext.vim has been correctly configured, a simple test
is to run the command, :DBListTable.  If a list of tables is shown, you know
dbext.vim is working as expected.  If not, please consult the dbext.txt
documentation.

Assuming you have followed the dbext-tutorial you can press <C-C>t to
display a list of tables.  There is a delay while dbext is creating the table
list.  After the list is displayed press <C-W>.  This will remove both the
popup window and the table name already chosen when the list became active.

 4.3.1 Table Completion:			*sql-completion-tables*

Press <C-C>t to display a list of tables from within the database you
have connected via the dbext plugin.
NOTE: All of the SQL completion popups support typing a prefix before pressing
the key map.  This will limit the contents of the popup window to just items
beginning with those characters.

 4.3.2 Column Completion:			*sql-completion-columns*

The SQL completion plugin can also display a list of columns for particular
tables.  The column completion is triggered via <C-C>c.

NOTE: The following example uses <Right> to trigger a column list while
      the popup window is active.

Example of using column completion:
     - Press <C-C>t again to display the list of tables.
     - When the list is displayed in the completion window, press <Right>,
       this will replace the list of tables, with a list of columns for the
       table highlighted (after the same short delay).
     - If you press <Left>, this will again replace the column list with the
       list of tables.  This allows you to drill into tables and column lists
       very quickly.
     - Press <Right> again while the same table is highlighted.  You will
       notice there is no delay since the column list has been cached.  If you
       change the schema of a cached table you can press <C-C>R, which
       clears the SQL completion cache.
     - NOTE: <Right> and <Left> have been designed to work while the
       completion window is active.  If the completion popup window is
       not active, a normal <Right> or <Left> will be executed.

Let's look at how we can build a SQL statement dynamically.  A select statement
requires a list of columns.  There are two ways to build a column list using
the SQL completion plugin. >
    One column at a time:
<       1. After typing SELECT press <C-C>t to display a list of tables.
	2. Choose a table from the list.
	3. Press <Right> to display a list of columns.
	4. Choose the column from the list and press enter.
	5. Enter a "," and press <C-C>c.  Generating a column list
	   generally requires having the cursor on a table name.  The plugin
	   uses this name to determine what table to retrieve the column list.
	   In this step, since we are pressing <C-C>c without the cursor
	   on a

Title: Dynamic SQL Completion Features and Table/Column Completion
Summary
This section continues the SQL completion tutorial, focusing on dynamic features that require the dbext.vim plugin. It explains how dbext connects to a database and how to verify the connection with ':DBListTable'. The tutorial details using `<C-C>t` to display a table list and `<C-C>c` to display column lists for tables. It also covers how to drill down from tables to columns using `<Right>` and back using `<Left>`, as well as how caching speeds up the process and how to clear the cache with `<C-C>R`. The section concludes with an example of dynamically building a SQL statement using column completion.