[SOLVED] how to connect to mysql with clisp and clsql?
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
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).
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:
So far, when testing the code, there are no errors reported... however, when I add the following line (the actual test) I get errors:
(asdf:oos 'asdf:load-op 'clsql-tests')
> (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... 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:
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.
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:
> (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
So I modified your suggestion accordingly, and it works!!!
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!