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."))))



(10 comments) - (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)

License on the extension functions
(Anonymous)
2008-08-11 08:32 am UTC (link)
Hi,
Thanks for making the extension-functions so easy to use with sqlite3. I was wondering, are the extension functions in the public domain as is sqlite?
Thanks very much,
Michael Janis
mjanis@chem.ucla.edu

(Reply to this) (Thread)

Re: License on the extension functions
[info]lhealy
2008-08-11 02:47 pm UTC (link)
The original code was sent to the sqlite mailing list by Mikey C with the closest thing to a license being "They are not fully tested and come with no warranty of fitness, but if anyone wants the code, please take it." I cleaned up and packaged and submitted to the contrib, under the same license :-)

Liam

(Reply to this) (Parent)(Thread)

Re: License on the extension functions
(Anonymous)
2008-08-11 06:16 pm UTC (link)
Thanks so much for your quick reply! I'll ask Mikey more about it.
-mjanis@chem.ucla.edu

(Reply to this) (Parent)(Thread)

Re: License on the extension functions
(Anonymous)
2008-08-14 01:11 am UTC (link)
After checking with Mikey C., the extension functions are indeed in the public domain. However, the code cleanup into a single loadable library file is quite instructive to me (I'm a student) and I really appreciate your efforts - it really makes inclusion of additional code, using the file as a template, trivial! I wonder, since you seem to have expert knowledge in this area, if I might trouble you with an additional question: I'd like to have automatic access to the external functions, by linking the functions to the sqlite3 source during compilation - after trying very hard to either bring the functions directly into sqlite3.c (not yet successful), or to link the extension functions into sqlite at compile time (it compiles, but doesn't recognize the external functions), I'm really at a loss. Do you have a suggestion that would help me understand how to create an executable (for starters, assuming I'm linking the shell.c code) that automatically registers all of the external functions? For example, something like (mingw)$gcc shell.c extension-functions.c sqlite.c -o sqlite3.exe -O2

Sorry if this is a beginner's question - and I do appreciate that this is not the proper forum for such a question, but after scouring the sqlite wiki, documentation, etc. I just can't seem to get around this. Any suggestions at all would be very warmly welcomed.

Regards,

Michael Janis
mjanis@chem.ucla.edu

(Reply to this) (Parent)(Thread)

Re: License on the extension functions
[info]lhealy
2008-08-14 01:35 pm UTC (link)
I think it should be possible, but you might have to make modifications to the sqlite loader. I'm not the one to ask though, I haven't looked at the sqlite source code nor even compiled it. You should probably post this question on the sqlite mailing list.

(Reply to this) (Parent)

Undefined symbol _sqlite3_result_error_nomem
(Anonymous)
2009-08-10 09:02 pm UTC (link)
I downloaded the file extension-functions.c from http://sqlite.org/contrib and tried to compile the file on a MacPro with MacOSX 10.5.7 using the command line in the extension-functions.c file:

gcc -fno-common -dynamiclib extension-functions.c -I /usr/local/include/ -L/usr/local/lib -lsqlite3 -o libsqlitefunctions.dylib


and I get the following error below. Can you provide any pointers as to what the problem is?

Jim

Undefined symbols:
"_sqlite3_result_error_nomem", referenced from:
_replicateFunc in ccGjWMEx.o
_properFunc in ccGjWMEx.o
_padlFunc in ccGjWMEx.o
_padlFunc in ccGjWMEx.o
_padrFunc in ccGjWMEx.o
_padrFunc in ccGjWMEx.o
_padcFunc in ccGjWMEx.o
_padcFunc in ccGjWMEx.o
_strfilterFunc in ccGjWMEx.o
_leftFunc in ccGjWMEx.o
_rightFunc in ccGjWMEx.o
_reverseFunc in ccGjWMEx.o
ld: symbol(s) not found
collect2: ld returned 1 exit status



(Reply to this) (Thread)

Re: Undefined symbol _sqlite3_result_error_nomem
(Anonymous)
2009-08-10 09:34 pm UTC (link)
In one of the threads on this subject: http://lhealy.livejournal.com/6306.html
it is mentioned that one needs to provide a path to the sqlite source:

gcc -Isqlite -Isqlite/src -fPIC func_ext.c map.c -shared -o libsqlitefunctions.so

I should mention that what I am trying to do is add trig functions to the sqlite that
is called with the sqlite API and used within Xcode when building iPhone applications.

1) Do I need to download the sqlite source and build my own sqlite to use trig functions
from within Xcode when building iPhone apps? Or

2) Is the SQLite source in a directory already on Mac Pro's for Max OSX?

Thanks,

Jim

(Reply to this) (Parent)(Thread)

Re: Undefined symbol _sqlite3_result_error_nomem
(Anonymous)
2009-08-11 04:19 pm UTC (link)
I was able to get it to compile by providing the path to the sqlite source.

(Reply to this) (Parent)


(10 comments) - (Post a new comment)

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