SBCL & MySQL (clsql, cffi)

Discussion of Common Lisp
erazer
Posts: 7
Joined: Wed Dec 15, 2010 12:59 am
Location: Poltava, Ukraine
Contact:

SBCL & MySQL (clsql, cffi)

Post by erazer » Wed Dec 15, 2010 1:36 am

Hello!

I want to interconnect sbcl and mysql. I have installed required packets with clbuild.

Then I do:

(require :asdf)
(asdf:operate 'asdf:load-op 'clsql)
(use-package :clsql-user)
(connect `("host" "dbname" "root" "password") :database-type :mysql)

And it says me:

debugger invoked on a TYPE-ERROR in thread #<THREAD "initial thread" RUNNING
{1002DA3EA1}>:
The value
(BABEL:STRING-SIZE-IN-OCTETS "SET SESSION sql_mode='ANSI'" :ENCODING
(OR NIL CFFI:*DEFAULT-FOREIGN-ENCODING*))
is not of type
(UNSIGNED-BYTE 32).

Type HELP for debugger help, or (SB-EXT:QUIT) to exit from SBCL.

restarts (invokable by number or by possibly-abbreviated name):
0: [ABORT] Exit debugger, returning to top level.

((FLET #:G386) #.(SB-SYS:INT-SAP #X00641B80))
0] 0

I have tried to do:

* (setf cffi:*default-foreign-encoding* :cp1251)
:CP1251

I have set different encoding values: utf8,cp1251,ansi - it doesn't matter and I have the same result.

Actually the question: how to fight with this? What it want to say to me and how to do it right way?

Thank you!

p.s. I have installed required packets with clbuild - all packets are last stable versions from repos. I have tried it on Fedora and Ubuntu. I have fail to install packets with ASDF but I have installed them with clbuild OK. The result is the same with both OS's.
“To avoid criticism do nothing, say nothing, be nothing.”- Elbert Hubbard
personal blog - developer in Ukraine

ramarren
Posts: 613
Joined: Sun Jun 29, 2008 4:02 am
Location: Warsaw, Poland
Contact:

Re: SBCL & MySQL (clsql, cffi)

Post by ramarren » Wed Dec 15, 2010 2:14 am

I have not experience with clsql, but don't you have to load a clsql-mysql backend specific system explicitly?

Also, I think the best way to install systems right now is quicklisp, despite being still marked as beta.

erazer
Posts: 7
Joined: Wed Dec 15, 2010 12:59 am
Location: Poltava, Ukraine
Contact:

Re: SBCL & MySQL (clsql, cffi)

Post by erazer » Wed Dec 15, 2010 6:03 am

Ramarren wrote:I have not experience with clsql, but don't you have to load a clsql-mysql backend specific system explicitly?
I think load cl-sql is just enough. Because when I set incorrect login/password pair it says: "Access denied for user 'root'@'localhost' (using password: YES)". So I think clsql works properly and it tires to connect to mysql. Maybe this is problem with babel or something else. I don't know.
Also, I think the best way to install systems right now is quicklisp, despite being still marked as beta.
As I understood this is just a packer manager? Something like clbuild or ASDF?
“To avoid criticism do nothing, say nothing, be nothing.”- Elbert Hubbard
personal blog - developer in Ukraine

ramarren
Posts: 613
Joined: Sun Jun 29, 2008 4:02 am
Location: Warsaw, Poland
Contact:

Re: SBCL & MySQL (clsql, cffi)

Post by ramarren » Wed Dec 15, 2010 7:27 am

erazer wrote:As I understood this is just a packer manager? Something like clbuild or ASDF?
Clbuild and ASDF have different purpose, and in fact clbuild uses asdf. ASDF is a system definition facility, a sort of equivalent to make, which is responsible for compiling and loading files that compose a system. CLbuild is a script used to download those files from repositories. But it doesn't really qualify as a "manager", since it doesn't really manage anything. Quicklisp stores its own copies of systems, and they are much more likely to be in version which work together. It also uses ASDF to load systems, although it creates a hook that automatically downloads missing dependencies.

erazer
Posts: 7
Joined: Wed Dec 15, 2010 12:59 am
Location: Poltava, Ukraine
Contact:

Re: SBCL & MySQL (clsql, cffi)

Post by erazer » Wed Dec 15, 2010 7:50 am

Thank you.
I just tried to use quicklisp now.
So...
I have deinstalled BSCL at all and install it again.
Then I use quicklisp to install cl-mysql
Then I try to connect to mysql server:

(cl-mysql:connect "127.0.0.1" "dbname" "root" "password")

And what it says to me:

debugger invoked on a SB-INT:SIMPLE-PROGRAM-ERROR in thread #<THREAD
"initial thread" RUNNING
{1002DA3E41}>:
unknown &KEY argument: "127.0.0.1"

Type HELP for debugger help, or (SB-EXT:QUIT) to exit from SBCL.

restarts (invokable by number or by possibly-abbreviated name):
0: [ABORT] Exit debugger, returning to top level.

(COM.HACKINGHAT.CL-MYSQL-SYSTEM:CONNECT)[:EXTERNAL]
0] 0

What am I doing wrong now? How to use connect function properly? Help me, please
“To avoid criticism do nothing, say nothing, be nothing.”- Elbert Hubbard
personal blog - developer in Ukraine

erazer
Posts: 7
Joined: Wed Dec 15, 2010 12:59 am
Location: Poltava, Ukraine
Contact:

Re: SBCL & MySQL (clsql, cffi)

Post by erazer » Wed Dec 15, 2010 8:26 am

I did it...

(cl-mysql:connect :host "localhost" :database "dbname" :user "root" :password "password")
(cl-mysql:query "select * from status limit 10" :store nil)

But how to get the result?...
“To avoid criticism do nothing, say nothing, be nothing.”- Elbert Hubbard
personal blog - developer in Ukraine

ramarren
Posts: 613
Joined: Sun Jun 29, 2008 4:02 am
Location: Warsaw, Poland
Contact:

Re: SBCL & MySQL (clsql, cffi)

Post by ramarren » Wed Dec 15, 2010 8:37 am

The clsql-mysql system is a backend. Your load the backed appropriate to the database you want to use, although from what I can see clsql tries to load a proper system automatically, but you interact directly with the frontend, which is the main clsql system. That is, the clsql:connect with MySQL specific connection specification. And generally. I don't think using the backend directly is recommended. Best read the manual.

vanekl
Posts: 12
Joined: Wed Dec 15, 2010 10:25 am

Re: SBCL & MySQL (clsql, cffi)

Post by vanekl » Wed Dec 15, 2010 10:39 am

CL-USER> (clsql:connect '("localhost" "mysql" "root" "password") :database-type :mysql :if-exists :old)
#<MYSQL-DATABASE localhost/mysql/root OPEN #x1884FB06>
CL-USER> (let ((query "select * from db "))
(clsql:do-query ((&rest field-vals) query)
(prin1 field-vals)))
("%" "test" "" "Y" "Y" "Y" "Y" "Y" "Y" "N" "Y" "Y" "Y" "Y" "Y" "Y" "Y" "Y" "N" "N")("%" "test\\_%" "" "Y" "Y" "Y" "Y" "Y" "Y" "N" "Y" "Y" "Y" "Y" "Y" "Y" "Y" "Y" "N" "N")

erazer
Posts: 7
Joined: Wed Dec 15, 2010 12:59 am
Location: Poltava, Ukraine
Contact:

Re: SBCL & MySQL (clsql, cffi)

Post by erazer » Wed Dec 15, 2010 12:58 pm

thank you

but this is for clsql

as I have fail with clsql connection (see firs message) I have installed cl-mysql (from http://www.hackinghat.com/index.php/cl-mysql) and now trying to get it work.

I can connect to DB via cl-mysql

(cl-mysql:connect :host "localhost" :database "dbname" :user "root" :password "password")

...and do a query

(cl-mysql:query "select * from status limit 10" :store nil)

But I don't understand how to get the result from the query. I think clsql and cl-mysql are just different in this way.

May be you can help me?

Thank you.
“To avoid criticism do nothing, say nothing, be nothing.”- Elbert Hubbard
personal blog - developer in Ukraine

ramarren
Posts: 613
Joined: Sun Jun 29, 2008 4:02 am
Location: Warsaw, Poland
Contact:

Re: SBCL & MySQL (clsql, cffi)

Post by ramarren » Wed Dec 15, 2010 1:13 pm

erazer wrote:but this is for clsql
Sorry, I misread, because I wasn't really aware cl-mysql existed. I don't have MySQL even installed on my system, so I cannot test it.
erazer wrote:But I don't understand how to get the result from the query.
The documentation on the very page you linked appears reasonably clear. What is it that you don't understand about it?

Post Reply