sqlite3 binding of Emacs Lisp
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
test More comment Feb 4, 2017
Makefile Improve setting default Emacs path for macOS Jan 30, 2017
README.md Use same interface both sqlite3-execute and sqlite3-execute-batch Feb 1, 2017
sqlite3-core.c Suppress compiler warning Feb 4, 2017
sqlite3.el Fix not clear callback variable issue Feb 3, 2017



sqlite binding of Emacs Lisp inspired by mruby-sqlite3


(require 'sqlite3)

  (with-current-buffer (get-buffer-create "*sqlite*")

  (let ((db (sqlite3-new "example/example.db")))
    (sqlite3-execute-batch db "CREATE TABLE foo(id integer primary key, editor text);")
    (sqlite3-execute-batch db "INSERT INTO foo(editor) values(?)" ["Vim"])
    (sqlite3-execute-batch db "INSERT INTO foo(editor) values(?)" ["Emacs"])
    (sqlite3-execute-batch db "INSERT INTO foo(editor) values(?)" ["Atom"])
    (sqlite3-execute-batch db "INSERT INTO foo(editor) values(?)" ["Notepad"])

     "SELECT * FROM foo"
     (lambda (row fields)
       (let ((id (car row))
             (editor (cadr row)))
         (with-current-buffer (get-buffer "*sqlite*")
           (insert (format "@@ ID=%d, Editor=%s\n" id editor))))))
    (pop-to-buffer (get-buffer "*sqlite*"))))


(sqlite3-new &optional db-path)

Create sqlite3 instance. If db-path is omitted, data is stored in memory.

(sqlite3-execute-batch db query &optional bounds)

Execute SQL query for db database. First argument db must be sqlite3 instance. If you use placeholders in query, then you must pass bounds too.

(sqlite3-execute db query &rest args)

Interface for executing SELECT query.

Rest parameters are bounds and callback. You can its argument as, either '(bounds) or '(callback) or '(bounds callback). callback function is called with database row. `callback' takes two arguments, first argument is row element of list, second argument is field names of list.

(sqlite3-resultset-next resultset)

Return next row.

(sqlite3-resultset-fields resultset)

Return fields name of row.

(sqlite3-resultset-eof resultset)

Return t if there is no more row.