Thursday, February 26, 2009

fbsql: Clean client-libraries for Firebird and Interbase databases

I've written this quite some time ago (and it didn't receive much love since then, but it's functional and should be bug-free), but I just noticed I haven't mentioned it on my blog: fbsql is a clean C-API that can be used to create bindings for other languages (such as Python or Ruby). It's much simpler to use than the raw Interbase/Firebird API and it uses IBPP internally. So it's basically just forwarding the function calls to IBPP and abstracting the IBPP classes to a C interface that is straight forward and intuitive.


I have included a binding to Lisp, since this was my personal main goal with this project. I noticed that there is no way at all to access Interbase and/or Firebird from Lisp, and since I like toying around with Lisp, I thought that writing small database helper applications with it is a good way to get comfortable with it. The Lisp binding has two layers: First is the CFFI that is used to access the native C functions from the fbsql C-library and the second, more lispish layer is a bit more advanced and better to use. It includes thinks like


(with-statement (st database transaction)
(statement-prepare st "select * from table")
(statement-execute st)
(while-statement-fetch st
(format t "~a~%" (statement-get-short st 1))))
This little script creates a statement to the given database and transaction, executes "select * from test" and prints everything value in column 1 (which should be a short).
Lisp is so wonderfully compact. ;-)