Liam Healy ([info]lhealy) wrote,
@ 2007-09-29 15:45:00
Previous Entry  Add to memories!  Tell a Friend!  Next Entry
Entry tags:lisp, sqlite

Extension functions in sqlite3, again
I mentioned before that I cleaned up and posted mathematical and string extension functions for SQLite3. Some things have changed in the interim, which necessitated going through a few revisions. So now the new version is available which makes compilation and use easier. For one thing, the SQLite source is no longer required to compile it. Second, it uses the standard sqlite3_load_extension interface, which should make it easier to use. The interface through CL using CLSQL is now

(in-package :sqlite3)

;;; Add mathematical and string functions to SQL queries using
;;; libsqlitefunctions from
;;; http://www.sqlite.org/contrib/download/extension-functions.c?get=22

(def-sqlite3-function
    "sqlite3_enable_load_extension"
    ((db sqlite3-db) (onoff :int))
 :returning :int)

(def-sqlite3-function
    "sqlite3_load_extension"
    ((db sqlite3-db)
     (filename :cstring)
     (entrypoint :int)
     (errmsg :int))
  :returning :int)

(eval-when  (:compile-toplevel :load-toplevel :execute)
  (export 'enable-sqlite3-extension-functions))

(defun enable-sqlite3-extension-functions (database)
  "Set up the SQLite3 mathematical extension functions.  This
   must be called every time the database is connected
   before any extension function is used."
  (let ((db-ptr (clsql-sqlite3::sqlite3-db database)))
    (sqlite3-enable-load-extension db-ptr 1)
    (unless (zerop
	     (sqlite3-load-extension db-ptr "libsqlitefunctions.so" 0 0))
      (error "Can't load libsqlitefunctions.so."))))


(Post a new comment)

error downloading
[info]pvb_livejournal
2008-03-03 11:58 am UTC (link)
Hi,

I was trying to download the extension using the given link (sqlite http://sqlite.org/contrib/download/extension-functions.c?get=22, but it returns an error 'ERROR: attempt to write a readonly database'. In fact I get the same message when downloading other extension from that page, except the compressed files (zip, tar.gz).

Is there another way to download this file?

Do I understand it correctly that this extension can simple by installed using the statement SELECT sqlite3_load_extension('filename') ?

Thanks

Paulo

(Reply to this)(Thread)

Re: error downloading
[info]lhealy
2008-03-05 03:58 pm UTC (link)
There is a known bug on the sqlite.org website, they should fix that soon.
You will need to compile the file into a library, and then follow the instructions which are given as a comment at the top of the file.

(Reply to this)(Parent)


Create an Account
Forgot your login?
Login w/ OpenID
English • Español • Deutsch • Русский…