How to connect LISP with Mysql database?

Discussion of Common Lisp

How to connect LISP with Mysql database?

Postby nitinkapoor25 » Tue Jan 27, 2009 10:23 am

Hi,

I want to connect LISP with Mysql database. I am using the below mentioned code in the file database.lisp. When I compile and losd the file 'database.lisp', it is giving the error message.
I already created the database and table in mysql.

CODE:
-------------------
(push #P"/usr/share/common-lisp/systems/" asdf:*central-registry*)
(asdf:operate 'asdf:load-op 'clsql)
(clsql:connect '("" "database_name" "user_name" "password") :database-type :mysql)
(clsql-sys:query "SELECT * FROM table_name")
-------------------
Thanks & Regards
Nitin
nitinkapoor25
 
Posts: 11
Joined: Mon Jan 05, 2009 10:17 am

Re: How to connect LISP with Mysql database?

Postby dmitry_vk » Tue Jan 27, 2009 10:41 am

nitinkapoor25 wrote:it is giving the error message.

What error message is given?
dmitry_vk
 
Posts: 96
Joined: Sat Jun 28, 2008 8:01 am
Location: Russia, Kazan

Re: How to connect LISP with Mysql database?

Postby nitinkapoor25 » Tue Jan 27, 2009 11:16 am

Hi,

Below is the error message.

----------------------------------------------

The value NIL
is not of type
(OR (VECTOR CHARACTER) (VECTOR NIL) BASE-STRING PATHNAME
STREAM).
[Condition of type TYPE-ERROR]

Restarts:
0: [ABORT] Return to SLIME's top level.
1: [TERMINATE-THREAD] Terminate this thread (#<THREAD "repl-thread" RUNNING {A883699}>)

Backtrace:
0: (LOAD NIL)[:EXTERNAL]
Locals:
SB-DEBUG::ARG-0 = 1
SB-DEBUG::ARG-1 = NIL
1: (SB-INT:SIMPLE-EVAL-IN-LEXENV (LOAD (COMPILE-FILE "database.lisp")) #<NULL-LEXENV>)
Locals:
SB-DEBUG::ARG-0 = (LOAD (COMPILE-FILE "database.lisp"))
SB-DEBUG::ARG-1 = #<NULL-LEXENV>
2: (SWANK::EVAL-REGION "(load (compile-file \"database.lisp\"))
")
Locals:
SB-DEBUG::ARG-0 = "(load (compile-file \"database.lisp\"))
"
3: ((LAMBDA NIL))
[No Locals]
4: (SWANK::TRACK-PACKAGE #<CLOSURE (LAMBDA NIL) {ACEE8ED}>)
Locals:
SB-DEBUG::ARG-0 = #<CLOSURE (LAMBDA NIL) {ACEE8ED}>
5: ((LAMBDA (SWANK-BACKEND::FN)) #<CLOSURE (LAMBDA NIL) {ACEE8D5}>)
Locals:
SWANK-BACKEND::FN = #<CLOSURE (LAMBDA NIL) {ACEE8D5}>
6: (SWANK::CALL-WITH-BUFFER-SYNTAX #<CLOSURE (LAMBDA NIL) {ACEE8D5}>)
Locals:
SB-DEBUG::ARG-0 = #<CLOSURE (LAMBDA NIL) {ACEE8D5}>
7: (SWANK::REPL-EVAL "(load (compile-file \"database.lisp\"))
")
Locals:
SB-DEBUG::ARG-0 = "(load (compile-file \"database.lisp\"))
"
8: (SB-INT:SIMPLE-EVAL-IN-LEXENV (SWANK:LISTENER-EVAL "(load (compile-file \"database.lisp\"))
") #<NULL-LEXENV>)
Locals:
SB-DEBUG::ARG-0 = (SWANK:LISTENER-EVAL "(load (compile-file \"database.lisp\"))
")
SB-DEBUG::ARG-1 = #<NULL-LEXENV>
9: ((LAMBDA NIL))
[No Locals]
10: ((FLET #:FORM-FUN1570))
Locals:
SWANK-BACKEND::FUN = #<CLOSURE (LAMBDA NIL) {ACEE83D}>
11: ((FLET #:FORM-FUN1570))
Locals:
SWANK-BACKEND::FUN = #<CLOSURE (LAMBDA NIL) {ACEE83D}>
12: ((LAMBDA (SWANK-BACKEND::HOOK SWANK-BACKEND::FUN)) #<FUNCTION SWANK:SWANK-DEBUGGER-HOOK> #<CLOSURE (LAMBDA NIL) {ACEE83D}>)
Locals:
SB-KERNEL:*HANDLER-CLUSTERS* = :<NOT-AVAILABLE>
SWANK-BACKEND::FUN = #<CLOSURE (LAMBDA NIL) {ACEE83D}>
SWANK-BACKEND::HOOK = #<FUNCTION SWANK:SWANK-DEBUGGER-HOOK>
13: ((LAMBDA NIL))
[No Locals]
14: ((FLET #:FORM-FUN1570))
Locals:
SWANK-BACKEND::FUN = #<FUNCTION (LAMBDA NIL) {B9ABE15}>
15: ((FLET #:FORM-FUN1570))
Locals:
SWANK-BACKEND::FUN = #<FUNCTION (LAMBDA NIL) {B9ABE15}>
16: ((LAMBDA (SWANK-BACKEND::HOOK SWANK-BACKEND::FUN)) #<FUNCTION SWANK:SWANK-DEBUGGER-HOOK> #<FUNCTION (LAMBDA NIL) {B9ABE15}>)
Locals:
SB-KERNEL:*HANDLER-CLUSTERS* = :<NOT-AVAILABLE>
SWANK-BACKEND::FUN = #<FUNCTION (LAMBDA NIL) {B9ABE15}>
SWANK-BACKEND::HOOK = #<FUNCTION SWANK:SWANK-DEBUGGER-HOOK>
17: (SWANK::CALL-WITH-REDIRECTED-IO #<SWANK::CONNECTION {B3AC001}> #<CLOSURE (LAMBDA NIL) {ACEE7A5}>)
Locals:
SB-DEBUG::ARG-0 = #<SWANK::CONNECTION {B3AC001}>
SB-DEBUG::ARG-1 = #<CLOSURE (LAMBDA NIL) {ACEE7A5}>
18: (SWANK::CALL-WITH-CONNECTION #<SWANK::CONNECTION {B3AC001}> #<FUNCTION (LAMBDA NIL) {B9ABE15}>)
Locals:
SB-DEBUG::ARG-0 = #<SWANK::CONNECTION {B3AC001}>
SB-DEBUG::ARG-1 = #<FUNCTION (LAMBDA NIL) {B9ABE15}>
19: (SWANK::HANDLE-REQUEST #<SWANK::CONNECTION {B3AC001}>)
Locals:
SB-DEBUG::ARG-0 = #<SWANK::CONNECTION {B3AC001}>
20: (SWANK::REPL-LOOP #<SWANK::CONNECTION {B3AC001}>)
Locals:
SB-DEBUG::ARG-0 = #<SWANK::CONNECTION {B3AC001}>
21: (SWANK::REPL-LOOP #<SWANK::CONNECTION {B3AC001}>)[:EXTERNAL]
Locals:
SB-DEBUG::ARG-0 = 1
SB-DEBUG::ARG-1 = #<SWANK::CONNECTION {B3AC001}>
22: (SWANK::CALL-WITH-BINDINGS NIL #<CLOSURE (LAMBDA NIL) {A88907D}>)
Locals:
SB-DEBUG::ARG-0 = NIL
SB-DEBUG::ARG-1 = #<CLOSURE (LAMBDA NIL) {A88907D}>
23: ((FLET SB-THREAD::WITH-MUTEX-THUNK))
[No Locals]
Catch-tags:
SB-IMPL::%END-OF-THE-WORLD
SB-INT:TOPLEVEL-CATCHER
24: ((FLET #:WITHOUT-INTERRUPTS-BODY-[CALL-WITH-MUTEX]477))
[No Locals]
25: (SB-THREAD::CALL-WITH-MUTEX #<CLOSURE (FLET SB-THREAD::WITH-MUTEX-THUNK) {B6447215}> #S(SB-THREAD:MUTEX :NAME "thread result lock" :%OWNER #<SB-THREAD:THREAD "repl-thread" RUNNING {A883699}> :STATE 1) #<SB-THREAD:THREAD "repl-thread" RUNNING {A883699}> T)
Locals:
SB-DEBUG::ARG-0 = #<CLOSURE (FLET SB-THREAD::WITH-MUTEX-THUNK) {B6447215}>
SB-DEBUG::ARG-1 = #S(SB-THREAD:MUTEX :NAME "thread result lock" :%OWNER #<SB-THREAD:THREAD "repl-thread" RUNNING {A883699}> :STATE 1)
SB-DEBUG::ARG-2 = #<SB-THREAD:THREAD "repl-thread" RUNNING {A883699}>
SB-DEBUG::ARG-3 = T
26: ((LAMBDA NIL))
[No Locals]
27: ("foreign function: #x8064EFC")
[No Locals]
28: ("foreign function: #x8052D31")
[No Locals]
29: ("foreign function: #x805C1AD")
[No Locals]
30: ("foreign function: #xB7FBA50F")
[No Locals]

----------------------------------------------

Regards
Nitin
nitinkapoor25
 
Posts: 11
Joined: Mon Jan 05, 2009 10:17 am

Re: How to connect LISP with Mysql database?

Postby nitinkapoor25 » Tue Jan 27, 2009 12:05 pm

If I enter the below code in the REPL. It connects to mysql database successfully and also display the data.
-----------------------------------------------
(push #P"/usr/share/common-lisp/systems/" asdf:*central-registry*)
(asdf:operate 'asdf:load-op 'clsql)
(clsql:connect '("" "database_name" "user_name" "password") :database-type :mysql)
(clsql-sys:query "SELECT * FROM table_name")
-----------------------------------------------
Thanks & Regards
Nitin
nitinkapoor25
 
Posts: 11
Joined: Mon Jan 05, 2009 10:17 am

Re: How to connect LISP with Mysql database?

Postby dmitry_vk » Tue Jan 27, 2009 12:08 pm

It seems that (compile-file "database.lisp") returned NIL. That means that compiling the file failed. See the output of (compile-file "database.lisp") to see the actual error.
dmitry_vk
 
Posts: 96
Joined: Sat Jun 28, 2008 8:01 am
Location: Russia, Kazan

Re: How to connect LISP with Mysql database?

Postby dmitry_vk » Tue Jan 27, 2009 12:14 pm

nitinkapoor25 wrote:(push #P"/usr/share/common-lisp/systems/" asdf:*central-registry*)
(asdf:operate 'asdf:load-op 'clsql)
(clsql:connect '("" "database_name" "user_name" "password") :database-type :mysql)
(clsql-sys:query "SELECT * FROM table_name")

I now understood.
The (asdf:operate 'asdf:load-op 'clsql) operates at run-time, but the clsql package must be available at compile-time to compile the call to clsql:connect. So, you should wrap the first two forms in eval-when:
Code: Select all
(eval-when (:compile-toplevel :load-toplevel :execute)
  (push #P"/usr/share/common-lisp/systems/" asdf:*central-registry*)
  (asdf:operate 'asdf:load-op 'clsql))
(clsql:connect '("" "database_name" "user_name" "password") :database-type :mysql)
(clsql-sys:query "SELECT * FROM table_name")

This way the clsql package will be available at compile-time
dmitry_vk
 
Posts: 96
Joined: Sat Jun 28, 2008 8:01 am
Location: Russia, Kazan

Re: How to connect LISP with Mysql database?

Postby nitinkapoor25 » Wed Jan 28, 2009 10:49 am

Buddy, you are absolutely right. CLSQL package not found when I compiled my code. I have used the code provided by you it is giving the below error message during compilation. It seems to me that error message are same during compilation:
----------------------
; compiling file "/tmp/fileSDTLhv.lisp" (written 28 JAN 2009 11:12:10 PM):
; compilation aborted because of fatal error:
; READ failure in COMPILE-FILE:
; SB-INT:SIMPLE-READER-PACKAGE-ERROR at 14 (line 1, column 14) on #<SB-SYS:FD-STREAM for "file /tmp/fileSDTLhv.lisp" {ABCFF09}>:
; package "CLSQL" not found
; compilation aborted after 0:00:00
;
; compilation unit finished
; caught 1 fatal ERROR condition
----------------------

Can I re-install CLSQL or is there any workaround for this.

Regards
Nitin
nitinkapoor25
 
Posts: 11
Joined: Mon Jan 05, 2009 10:17 am

Re: How to connect LISP with Mysql database?

Postby nitinkapoor25 » Wed Jan 28, 2009 11:17 am

Thanks buddy, it is working now. I have installed "CLSQL - ODBC" and now I am able to compile the database.lisp file.

Thanks again

Nitin
nitinkapoor25
 
Posts: 11
Joined: Mon Jan 05, 2009 10:17 am


Return to Common Lisp

Who is online

Users browsing this forum: No registered users and 2 guests