пятница, 27 мая 2011 г.

LISP(SBCL) & MySQL. First spiritual experience

Next step of my journey into Lisp. I tried to create soft for myself, which I can use every day. Time to time I needed to read more and more manuals. And it gave results. Experience in the use of many structures Lisp comes with repeated usage. The "Praсtiсal Common Lisp" has become my desktop book. Many useful features are already implemented in this book have been used, and gave the key to understanding how to create these.
And one time, I tried to create function that use the standart unix terminal. 
So I list some forums and found out that SBCL have functions for communicating with MySQL. Its call "cl-mysql". It is the system for working with databases.
For using this, you need to install the "cl-mysql", for example through Quicklisp.
Lets proceed from the fact that you already have Quicklisp. Next you install the system:


(quicklisp-quickstart:install)
(ql:quickload "cl-mysql")


Now you can test the SQL functions in REPL:

  (cl-mysql:connect :host "localhost" :database "dbname" :user "root" :password "password")
(cl-mysql:query "select * from table")



For using this possibilities in action, I found only one way.


(ql:quickload "cl-mysql")
(defun test ()
     (cl-mysql:connect
      :host "localhost"
      :database "db"
      :user "root"
      :password "password")
       (cl-mysql:query "select * from test"))





Thats all for MySQL + SBCL, for this time.

Lets source be with you.