LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 10-28-2009, 12:50 PM   #1
globaltree
Member
 
Registered: Oct 2007
Location: Oregon
Distribution: Slackware 12.2
Posts: 65

Rep: Reputation: 18
how to connect to mysql with clisp and clsql?


Hello LQ:

Here is some background to the project I am working on... the next post contains the actual programming dilemma that I need help with:

Because of this poll, my son and I have been learning C together (though I have already been using php for many years). We made a command line interface to our mysql database, and it works! However, it is ugly, and my wife fears all of our black screens with textual gibberish, so, as an incentive to get her to enter our bills into our database, we want to wrap our mysql interface with a gui.

Although it is not too hard to make our c interface a cgi script, and use a web browser to access mysql (or to have done the whole thing in php in the first place), I wanted to do something I have never done before, so I wanted to try to use some kind of gui toolkit to create a multi-platform gui, as my wife runs osx, my son and I are running slackware, and my mother has winxp. So I did some dabbling: I made a window with gtk2, and liked it because it had C-API that was straight forward and documented, but I understand that the gnome based gtk/gtk+/gtk2 doesn't provide native look and feel in other os, and it took many lines of code to create that window... then I messed with qt, but it seemed too commercially geared for my foss consciousness, and it's API seemed more geared to C++ than C.

Then I tried tk. I like projects that have stood the test of time, and although it has a reputation for creating ugly gui, it has since added tile, which allows the look and feel to be derived from an os-specific theme, thus delivering the native look and feel. But, even though the entire tk seems to be written in C, it seems that you are supposed to use another language to access it, as most of the examples on the net use tcl, perl, python, or ruby to access tk. Although there probably is a way to, in C, manually fire up wish, the lack of examples lead me to think it is probably not a good idea: maybe they want to protect noobs from themselves, as array overflows, etc. in C can mess up your system and can be security vulnerabilities: therefore, make the noobs use higher-level language that handles memory allocation for them... just a guess, but if that's the case, C shouldn't be the leading contestant from the best beginning language poll, grr.

In my research of Tk, I learned that common lisp had a package ltk, and so started dabbling with CL, another project that has stood the test of time. Sure there are lots of parentheses, but there is something I liked about it: it's being based on lamda calculus makes it seem more like math and symbolic logic... I mean what's the point of learning the powerful language of expression developed by mathematicians over the past millennium, if you go on to programming to find zillions of languages competing to accomplish the same tasks, each with their own gnitty-gritty ways of expressing logical relationships that have already been expressed in other more refined ways in math and logic. So I like lisp because it seems like that in addition to learning lisp, I am learning lamda calculus at same time! Plus, if nasa uses common lisp on their space shuttles, it should suffice for my family's address book.

So, trying to piece it all together from the scanty lisp documentation of dozens of different implementations of common lisp, I was able to get a functional lisp system going: I created /usr/local/lisp/asdf, and /usr/local/lisp/src. I saved asdf.lisp in /usr/local/lisp/asdf, and then unpacked the source packages in /usr/local/lisp/src, and created symbolic links inside /usr/local/lisp/asdf to their respective .asd files inside their source packages in /usr/local/lisp/src. I ran a test and discovered that it works. I was able to load ltk and ltk-tile and create a test window. I moved it over to my wife's os x, and the window looked good there too, so I decided to proceed.

The problem is that I don't know how to wrap the c application my son and I created to access mysql with the lisp/ttk wrapper, and I have become so frustrated, that I thought it might be easier to just use common lisp for the entire project, meaning I need to connect to our mysql database the lisp way, which uses clsql, and I have, thus far been unsuccessful. The details follow in the next post. (Sorry, my degree in philosophy causes me to write too much, but if you made it with me this far, you hopefully will have found a 40-year-old/11-year-old father/son team trying to tackle lisp endearing enough to lend a helping thought).
 
Old 10-28-2009, 01:28 PM   #2
globaltree
Member
 
Registered: Oct 2007
Location: Oregon
Distribution: Slackware 12.2
Posts: 65

Original Poster
Rep: Reputation: 18
dilimma with clisp, clsql, and mysql

So far, I have saved /usr/local/lisp/mylisp/mysqltest.lisp with the following contents:
Code:
(load "/usr/local/lisp/asdf/asdf")
(push #P"/usr/local/lisp/asdf/" asdf:*central-registry*)
(asdf:oos 'asdf:load-op 'alexandria)
(asdf:oos 'asdf:load-op 'babel)
(asdf:oos 'asdf:load-op 'trivial-features)
(asdf:oos 'asdf:load-op 'uffi)
(asdf:oos 'asdf:load-op 'md5)
(asdf:oos 'asdf:load-op 'clsql)
(asdf:oos 'asdf:load-op 'clsql-uffi)
(asdf:oos 'asdf:load-op 'clsql-mysql)
As per the documentation, I also set saved ~/.clsql-test-config with the following, though replacing the mysqlhost, db, dbuser, dbsecret, with the actual info that's already working in our C app interface:
Code:
((:mysql ("mysqlhost" "db" "dbuser" "dbsecret"))
(:aodbc ("my-dsn" "a-user" "pass"))
(:postgresql ("localhost" "another-db" "user2" "dont-tell"))
(:postgresql-socket ("pg-server" "a-db-name" "user" "secret-password"))
(:sqlite ("path-to-sqlite-db")))
So far, when testing the code, there are no errors reported... however, when I add the following line (the actual test) I get errors:

Code:
(asdf:oos 'asdf:load-op 'clsql-tests')
returns:

Code:
[11]> (asdf:oos 'asdf:load-op 'clsql-tests')

*** - READ from #<INPUT CONCATENATED-STREAM #<INPUT STRING-INPUT-STREAM> #<IO TERMINAL-STREAM>>: an
      object cannot start with #\)
The following restarts are available:
ABORT          :R1      Abort main loop
So the test maybe has a bug...
 
Old 10-28-2009, 01:52 PM   #3
globaltree
Member
 
Registered: Oct 2007
Location: Oregon
Distribution: Slackware 12.2
Posts: 65

Original Poster
Rep: Reputation: 18
what loads sql.lisp?

So, forgetting clsql-test that came with the package, as it had a bug, and I don't want to debug their test, I just moved on to trying to connect as per the clsql documentation.

After loading the part that works from above, I then tried the following, and got a new error:
Code:
(connect '("mysql.host" "mysqldatabase" "mysqluser" "mysqlsecret") :database-type :mysql))

*** - EVAL: undefined function CONNECT
So... after opening up lots of .lisp files and searching for "connect" I found that the function is defined in /usr/local/lisp/src/clsql-4.1.1/sql/database.lisp". However, I can't figure out which of the .asd files actually loads this sql/database.lisp file. The only .asd files in clsql source tree are:

clsql-4.1.1/clsql-uffi.asd
clsql-4.1.1/clsql-mysql.asd
clsql-4.1.1/clsql-tests.asd
clsql-4.1.1/clsql.asd
clsql-4.1.1/clsql-db2.asd
clsql-4.1.1/clsql-sqlite3.asd
clsql-4.1.1/clsql-postgresql.asd
clsql-4.1.1/clsql-aodbc.asd
clsql-4.1.1/clsql-postgresql-socket.asd
clsql-4.1.1/clsql-oracle.asd
clsql-4.1.1/clsql-sqlite.asd
clsql-4.1.1/clsql-odbc.asd

It doesn't seem like I should load the .asd files for the other databases, so so far I have only used loaded clsql.asd, clsql-uffi.asd, and clsql-mysql.asd. However, there must be something else as the main connect function is still undefined. Maybe I should try to manually load the .lisp files in clsql-4.1.1/sql...

Oh... I am not technically using the uffi.asd from the uffi package, because uffi doesn't support clisp (clisp came with slackware, so I am using it by default), however, my symbolic link in /usr/local/lisp/asdf points to /usr/local/lisp/src/cffi-0.10.5/uffi-compat/uffi.asd and this is purported to work with clisp.

So, if anyone out there has every successfully connected with this combo: clisp, clsql, and mysql, please, please, enlighten me.
 
Old 10-28-2009, 02:33 PM   #4
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian
Posts: 2,541

Rep: Reputation: 878Reputation: 878Reputation: 878Reputation: 878Reputation: 878Reputation: 878Reputation: 878
I haven't used clsql in particular, but I am somewhat familiar with Common Lisp.
Code:
(asdf:oos 'asdf:load-op 'clsql-tests')
The highlighted quote should not be there; single quotes should not be paired in Lisp.

Quote:
So... after opening up lots of .lisp files and searching for "connect" I found that the function is defined in /usr/local/lisp/src/clsql-4.1.1/sql/database.lisp".
Does that file have a statement like (in-package :clsql) at the top? I'm guessing that the connect function is defined in the clsql package, so to access it you should do
Code:
(clsql:connect '("mysql.host" "mysqldatabase" "mysqluser" "mysqlsecret") :database-type :mysql))
 
Old 10-28-2009, 03:26 PM   #5
globaltree
Member
 
Registered: Oct 2007
Location: Oregon
Distribution: Slackware 12.2
Posts: 65

Original Poster
Rep: Reputation: 18
Talking Solved

Thanks for responding, Ntubski. Though I hadn't understood it, I had noticed the unpaired single quotes being used, and wondered about them... I corrected the error and got another:

Code:
[13]> (asdf:oos 'asdf:load-op 'clsql-tests)
; loading system definition from /usr/local/lisp/asdf/clsql-tests.asd into #<PACKAGE ASDF0>
;; Loading file /usr/local/lisp/asdf/clsql-tests.asd ...
; registering #<SYSTEM CLSQL-TESTS #x2051777E> as CLSQL-TESTS
WARNING: The generic function #<STANDARD-GENERIC-FUNCTION PERFORM> is being modified, but has
         already been called.
;; Loaded file /usr/local/lisp/asdf/clsql-tests.asd
*** - component CLSQL-TESTS-SYSTEM::RT not found, required by #<SYSTEM "clsql-tests" #x2051777E>
The following restarts are available:
RETRY          :R1      Retry loading component CLSQL-TESTS-SYSTEM::RT.
ABORT          :R2      Abort main loop
However, it doesn't matter, because your suggestion worked, with only one small modification!!! Following up on connect, /usr/local/lisp/src/clsql-4.1.1/sql/database.lisp contained the line
Code:
(in-package #:clsql-sys)
So I modified your suggestion accordingly, and it works!!!

Code:
[16]> (clsql-sys:connect '("mysql.host" "mysqldb" "mysqluser" "mysqlsecret") :database-type :mysql)
#<CLSQL-MYSQL:MYSQL-DATABASE mysql.host/mysqldb/mysqluser OPEN #x20560356>
Big breath and sigh of relief. We've gone too far to turn back now, so it looks like common lisp is the higher level language we'll tackle: it's a challenge trying to stay a step ahead of my son. Thank you very very much for the quick response! LQ is the Best!
 
Old 10-28-2009, 07:16 PM   #6
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian
Posts: 2,541

Rep: Reputation: 878Reputation: 878Reputation: 878Reputation: 878Reputation: 878Reputation: 878Reputation: 878
Glad I could help.

Quote:
*** - component CLSQL-TESTS-SYSTEM::RT not found, required by #<SYSTEM "clsql-tests" #x2051777E>
Looks like it might require the RT test framework.
 
  


Reply

Tags
clisp, common, lisp, mysql


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ERROR 2002: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql. NoviceW Linux - Networking 17 09-17-2014 03:13 PM
Warning: mysql_connect() [function.mysql-connect]: Can't connect to local MySQL serve vinnyband Linux - Software 3 10-30-2008 03:53 PM
mysql error Can't connect to local MySQL server through socket '/var/lib/mysql/mysql. SpellChainz Linux - Newbie 1 06-23-2007 04:35 PM
mysql error Can't connect to local MySQL server through socket '/var/lib/mysql/mysql. Dannux Linux - Software 3 03-24-2006 09:44 AM


All times are GMT -5. The time now is 01:56 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration