Home Explore Blog CI



neovim

3rd chunk of `runtime/doc/ft_sql.txt`
5cb931edae4e418fd11616bd5424caf91654f90638d9fffc0000000100000fa3
 [CTRL-D


==============================================================================
2. SQL Dialects					*sql-dialects* *sql-types*
						*sybase* *TSQL* *Transact-SQL*
						*sqlanywhere*
						*oracle* *plsql* *sqlj*
						*sqlserver*
						*mysql* *postgresql* *psql*
						*informix*

All relational databases support SQL.  There is a portion of SQL that is
portable across vendors (ex. CREATE TABLE, CREATE INDEX), but there is a
great deal of vendor specific extensions to SQL.  Oracle supports the
"CREATE OR REPLACE" syntax, column defaults specified in the CREATE TABLE
statement and the procedural language (for stored procedures and triggers).

The default Vim distribution ships with syntax highlighting based on Oracle's
PL/SQL.  The default SQL indent script works for Oracle and SQL Anywhere.
The default filetype plugin works for all vendors and should remain vendor
neutral, but extendable.

Vim currently has support for a variety of different vendors, currently this
is via syntax scripts. Unfortunately, to flip between different syntax rules
you must either create:
    1.  New filetypes
    2.  Custom autocmds
    3.  Manual steps / commands

The majority of people work with only one vendor's database product, it would
be nice to specify a default in your |init.vim|.


------------------------------------------------------------------------------
2.1 SQLSetType					*sqlsettype* *SQLSetType*

For the people that work with many different databases, it is nice to be
able to flip between the various vendors rules (indent, syntax) on a per
buffer basis, at any time.  The ftplugin/sql.vim file defines this function: >
    SQLSetType

Executing this function without any parameters will set the indent and syntax
scripts back to their defaults, see |sql-type-default|.  You can use the <Tab>
key to complete the optional parameter.

After typing the function name and a space, you can use the completion to
supply a parameter.  The function takes the name of the Vim script you want to
source.  Using the |cmdline-completion| feature, the SQLSetType function will
search the |'runtimepath'| for all Vim scripts with a name containing "sql".
This takes the guess work out of the spelling of the names.  The following are
examples: >
    :SQLSetType
    :SQLSetType sqloracle
    :SQLSetType sqlanywhere
    :SQLSetType sqlinformix
    :SQLSetType mysql

The easiest approach is to the use <Tab> character which will first complete
the command name (SQLSetType), after a space and another <Tab>, display a list
of available Vim script names: >
    :SQL<Tab><space><Tab>


------------------------------------------------------------------------------
2.2 SQLGetType					*sqlgettype* *SQLGetType*

At anytime you can determine which SQL dialect you are using by calling the
SQLGetType command.  The ftplugin/sql.vim file defines this function: >
    SQLGetType

This will echo: >
    Current SQL dialect in use:sqlanywhere


------------------------------------------------------------------------------
2.3 SQL Dialect Default				*sql-type-default*

As mentioned earlier, the default syntax rules for Vim is based on Oracle
(PL/SQL).  You can override this default by placing one of the following in
your |init.vim|: >
    let g:sql_type_default = 'sqlanywhere'
    let g:sql_type_default = 'sqlinformix'
    let g:sql_type_default = 'mysql'

If you added the following to your |init.vim|: >
    let g:sql_type_default = 'sqlinformix'

The next time edit a SQL file the following scripts will be automatically
loaded by Vim: >
    ftplugin/sql.vim
    syntax/sqlinformix.vim
    indent/sql.vim
<
Notice indent/sqlinformix.sql was not loaded.  There is no indent file
for Informix, Vim loads the default files if the specified files does not
exist.


==============================================================================
3. Adding new SQL Dialects			*sql-adding-dialects*

If you begin working with a SQL dialect which does not have any customizations
available with

Title: SQL Dialects in Vim: Configuration and Customization
Summary
This section discusses how Vim handles different SQL dialects, acknowledging that while a portion of SQL is portable, vendor-specific extensions exist. It covers the challenges of switching between syntax rules for different vendors and introduces the `SQLSetType` function for changing syntax and indent scripts on a per-buffer basis. It also describes the `SQLGetType` function for determining the current SQL dialect and explains how to set a default SQL dialect in your `init.vim`.