sponsor Vim development Vim logo Vim Book Ad

vim-addon-sql : alias sensitive SQL completion (MySQL, Postgresql, SQLite)

 script karma  Rating 2/4, Downloaded by 2325  Comments, bugs, improvements  Vim wiki

created by
Marc Weber
script type
KISS implementation of SQL completion for Vim:

First you have to connect to a database. Examples:

  call vim_addon_sql#Connect('mysql',{'host':'','database':'DATABASE', 'user':'USER', 'password' : 'PASSWORT'})

  call vim_addon_sql#Connect('mysql',{'database':'filepath'})

  Postgresql (see code)

A connection only initializes b:db_conn which is a Vim object providing
functions for querying the database.

Setup mappings by calling this function:
  call vim_addon_sql#UI()

In non visual mode the query start / end is determined by either ; or empty lines.
In visual mode the selection will be executed

Execution is done by command line tools (psql, mysql, sqlite(3))
The result of those queries is parsed by Vim to fill alias aware completion.


  SELECT *, CURSOR FROM table1, table2
  Now CURSOR will only contain fields found in either table1 or table2

  SELECT *, a.CURSOR FROM table1 as a, table2
  Now the completion will only contain fields of table1

Expect some minor bugs - however this it works quite nicely in practise.

camel case like completion is also supported. eg d_u -> db_users

Also completes MySQL internal functions

If you have any questions contact me.
install details
The *info* file in the top level directory contains all dependencies. I recommend using vim-addon-manager to install them all at once

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
vim-addon-sql-0.2.4.zip 0.2.4 2011-05-10 7.0 Marc Weber firebird support
vim-addon-sql-0.2.3.zip 0.2.3 2011-03-15 7.0 Marc Weber mysql: also complete function names
vim-addon-sql-0.2.2.zip 0.2.2 2011-02-05 7.0 Marc Weber fix CamelCase alias field completion. Allow _ in names. Close error buffer if no error occured
vim-addon-sql-0.2.1.zip 0.2.1 2010-12-28 7.0 Marc Weber bugfix on aliases
vim-addon-sql-0.2.zip 0.2 2010-09-27 7.0 Marc Weber new release as vim-addon-sql. Sqlite and Postgres are supported. Code import from tovl
vimlib_sql_installer_sourceme.zip 0.0 2008-09-14 7.0 Marc Weber fixed quoting of *, using stdin now to pass SQL command, vl#dev#sql#sql#ThisSQLCommand()
can be overridden now
ip used for rating:

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.