Howdy,
I recently needed to retrieve some data from MySQL with Gambit. I wasn't able to find an MySQL FFI for Gambit, so I whipped up a simple API wrapper around the mysql command line tool:
http://bendiken.net/files/gambit/gambit-mysql-wrapper.tar.bz2
While certainly not a proper binding, it serves my purpose admirably and may perhaps be useful to others as well.
Usage is simple enough:
(define *user* "root") (define *passwd* "root")
(let* ((conn (mysql-connect user: *user* password: *passwd* db: "mysql")) (query "SELECT host, user, password FROM user") (result (mysql-query conn query))) (while (mysql-fetch-row result) (lambda (row) (pretty-print row))) (mysql-close conn))
More information is available from my blog post at:
http://bendiken.net/2006/06/11/poor-mans-mysql-api-for-gambit
Best regards from sunny Spain, Arto
Afficher les réponses par date
Arto Bendiken wrote:
I recently needed to retrieve some data from MySQL with Gambit. I wasn't able to find an MySQL FFI for Gambit, so I whipped up a simple API wrapper around the mysql command line tool:
You might be interested in the following:
http://okmij.org/ftp/Scheme/#databases
Particularly:
http://okmij.org/ftp/Scheme/#db.scripting
It's not for MySQL, but it's the same basic principle.
Anton
On 6/12/06, Anton van Straaten anton@appsolutions.com wrote:
Arto Bendiken wrote:
I recently needed to retrieve some data from MySQL with Gambit. I wasn't able to find an MySQL FFI for Gambit, so I whipped up a simple API wrapper around the mysql command line tool:
You might be interested in the following:
http://okmij.org/ftp/Scheme/#databases
Particularly:
http://okmij.org/ftp/Scheme/#db.scripting
It's not for MySQL, but it's the same basic principle.
Ah, indeed it seems that those who forget history are doomed to reinvent it. Thank you, Anton.
At 2:48 Uhr +0200 12.06.2006, Arto Bendiken wrote:
Howdy,
I recently needed to retrieve some data from MySQL with Gambit. I wasn't able to find an MySQL FFI for Gambit,
I don't know about a direct mysql binding either. But as I've written to this list earlier, one can also get at databases by using my Perl bindings "gperl" (and actually I'm using this now to access mysql).
Besides not requiring Perl, your approach will have the advantage, that when using multiple gambit threads running queries in parallel, one thread will not block the others, as is currently the case with the perl interface (and C bindings in general (unless special precautions are taken, possibly)).
I'd like to mention that I've continued development of "gperl", it can now read/write/create perl hashes. I'll release it when I find time to clean it up a bit; if anyone is interested sooner, write to me.
It would be interesting to know about the efficiency of both approaches. I'm also thinking about implementing bindings to postgres, which has a client library that allows handling connections asynchronously, which could solve the concurrency problem. (And writing direct bindings has the advantage that using real prepared statements become possible, something which at least Perl's DBD::mysql doesn't currently use.)
Christian.