sponsor Vim development Vim logo Vim Book Ad

sqlite.vim : Plugin that provides sqlite database access to vimscripts

 script karma  Rating 0/0, Downloaded by 1692  Comments, bugs, improvements  Vim wiki

created by
Alexandre Viau
script type
See latest version on github: https://github.com/viaa/VimPlugins

Plugin that provides sqlite database access to vimscripts. The script was not tested in Linux, but it does work in Windows.

Usage: Change the s:SqlitePath variable in this script to the path of your sqlite3 executable, then in your script set this variable to the path of your database let g:SVDbPath = '<path to my database>'. After that you can use any of the functions in this script to access sqlite:

SVReplaceChars(fileName) " Replace invalid filename characters
SVFormatCSVDates(monthPos) " Format the dates: if a day or month is less than 10 then add a 0 to have it compatible with Sqlite's date format (the dates formatted here have an initial format m/d/yyyy (d/m/yyyy could also be formatted)
SVImportCsv(tbl, path, separator, append, removeColumns, dropTable, createTableFromCsvColumns) " Import a CSV file
SVExe(type, out, stm) " Execute a SQL statement or a command script. May return the results if specified.
SVExportCsv(qry, path) " Export the file to csv
SVExportTab(qry, path) " Export the file to text separated by tabs
SVExportList(qry, path) " Export the file to list (each field is on its own line)
SVExportListPostProcessing() " Post processing (to make the file with the first field indented and the multiline text fields with all their text lines on the same line, the line of the field)
SVExportHtml(qry, path, decodeHtml) " Export a table/view to an html file
SVViewsToHtml(path, decodeHtml) " Export each views to 1 html files and create a frameset to navigate the views with a list (menu)
SVTables(out) " Show table list
SVSchema(out, tblName) " Show table(s) description(s). If no table name specified then all tables are described.
SVConvertListToCsv(path, fieldsToRemove, separator) " Format a file that is exported with g:SVExportList() to a CSV file for import
SVSqlColumnNames(sql) " Returns a list of column names for the given query
SVSqlLoop(sql, callbackFunction) " Loops the rows returned by a sql statement and for each rows it calls a callback function, passing to it a dictionnary that contains the names and values of each columns in that row.
SVSqlToFile(sql, filePath, mapInstructions, filterInstructions) " Write the result of a sql query to a file. The mapInstructions and filterIntstructions are lists of strings that will passed to the map() and filter() functions to do processing on the list before to save it.
SVCreateTableFromCsvFile(path, separator, tbl, dropTable) " Takes the columns on the first line of a csv file and makes a 'create table' statement out of it
SVDropTable(tbl) " To simply drop a table (helper function)

install details
Put the script in the vim plugin directory.

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
sqlite.vim 2.0 2016-11-10 7.0 Alexandre Viau Many changes
sqlite.vim 1.0 2016-03-24 7.0 Alexandre Viau Initial upload
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.
Vim at Github