Page 1 of 1

Mysql module

Posted: Thu Jan 22, 2009 5:37 pm
by Jeff
I just posted a new Mysql module that allows run-time creation of new, anonymous connections, multiple connections, automatic escaping and statement formatting, as well as a host of handy higher order functions to work with MySQL data sets.

Take a look and find any bugs you can!

http://www.artfulcode.net/articles/a-be ... r-newlisp/

Posted: Fri Jan 23, 2009 8:13 pm
by cormullion
I might have a go this weekend, Jeff. But I think I'm right in saying that there isn't a default installation of MySQL on MacOS X Leopard, so it might need to be installed. And sometimes that's not so easy...

But looking at the code is also instructive for me - I'm impressed at how you've integrated FOOP-styles...

Posted: Fri Jan 23, 2009 8:17 pm
by Jeff
You must have the libmysqlclient library for both the standard module and this one. There are OSX installers on msyql.com or it could be installed with fink or macports.

Posted: Mon Jan 26, 2009 10:34 pm
by cormullion
Well, I got this far:
ERR: problem loading library in function import : "dlopen(/usr/local/mysql/lib/libmysqlclient.dylib, 9): no suitable image found. Did find:\n\t/usr/local/mysql/lib/libmysqlclient.dylib: mach-o, but wrong architecture"
I think I did install it OK, though, because in the Terminal:

Code: Select all

mysql> status;
--------------
/usr/local/mysql/bin/mysql  Ver 14.14 Distrib 5.1.30, for apple-darwin9.5.0 (i386) using readline 5.1
I may spend some more time on it this week...!:)

Posted: Tue Jan 27, 2009 11:51 am
by Lutz
May be one of these:

http://newlisp.org/downloads/MacOSX-MySQL/

can help you (for version MySQL 5.0 but perhaps work for 5.1 too)

Posted: Tue Jan 27, 2009 5:13 pm
by Jeff
The client library should work independent of the server's minor version.

Posted: Wed Jan 28, 2009 8:22 pm
by cormullion
My mistake. I had downloaded the wrong one - it said 64, which I thought was right, but is wasn't - the other one was correct.

After that I got lost in the maze which is quite typical of open source software: 'fatal error', 'could not find', 'aborting', 'you need to run make install', 'permission denied' - all that terminal stuff that I last saw when trying to get TEX to work.

I'm just not clever enough (or have time enough) to test your module thoroughly. I hope others can help... :(

Posted: Wed Jan 28, 2009 9:29 pm
by Jeff
Uh, it has no dependencies that the standard mysql module does not have. If you can run that one, you can run mine... if you are using a mac, try looking up fink or macports for an easy way to install unix software.

Posted: Thu Jan 29, 2009 2:46 pm
by Lutz
Follow these instructions:

http://www.newlisp.org/downloads/MacOSX ... nstall.txt

worked for me out of the box with newLISP 10.0.1 and the installed /usr/share/newlisp/modules/mysql51.lsp module, and should work with Jeff's module too.

Posted: Thu Jan 29, 2009 6:10 pm
by cormullion
Jeff, I noticed these weird lines in http://static.artfulcode.net/newlisp/mysql.lsp.src.html

Code: Select all

("date " (apply date-valueue (map int (parse value "-"))))
 ("datetime" (apply date-valueue (map int (parse value "[-: ]" 0))))
...
 ("timestamp" (apply date-valueue (map int (parse value "[-: ]" 0))))
- that valueue thing looks wrong...

I wonder whether these are in the original or just the src.html file...?

My previous problems are because I don't know how to set up MySQL users or databases... Not your problem at all... :)

Posted: Thu Jan 29, 2009 7:01 pm
by Jeff
Corm,

Thanks for finding that! I've fixed the typo and re-upped the module.

Posted: Thu Jan 29, 2009 10:23 pm
by cormullion
I know this isn't a real bug, but if you run the example code on an empty table, you get this:

Code: Select all

newlisp(24462) malloc: *** error for object 0x105760: Non-aligned pointer being freed (2)
*** set a breakpoint in malloc_error_break to debug
newlisp(24462) malloc: *** error for object 0x105940: double free
*** set a breakpoint in malloc_error_break to debug
which I think occurs after this:

Code: Select all

(:free result) ; free the result set
OK, obviously it would be hard for somebody who knew what they were doing to do something as stupid as this - but I did it easily! :)

Posted: Fri Jan 30, 2009 2:32 am
by Jeff
Can you post the code you wrote that lead to that error?

Posted: Fri Jan 30, 2009 7:02 pm
by cormullion
after creating a table t3 in mysql command line:

Code: Select all

mysql> create table t3 (number INTEGER);
Query OK, 0 rows affected (0.08 sec)

mysql> 
i ran this in newlisp:

Code: Select all

(load {/Users/me/lisp/mysql.lsp})
(println (setf db (Mysql)))
(println (:connect db "localhost" "me@localhost" "" "test") )
(println (setf result (:query db "SELECT * FROM t3")))
(println (setf rows (:fetch-all result)))
(println (:free result))
(println (:close-db db))
which sometimes produces this error:

Code: Select all

newlisp(28509) malloc: *** error for object 0x105760: Non-aligned pointer being freed (2)
*** set a breakpoint in malloc_error_break to debug
newlisp(28509) malloc: *** error for object 0x105940: double free
*** set a breakpoint in malloc_error_break to debug
It's not a non-existent table - that gives:

Code: Select all

ERR: user error : Table 'test.t6' doesn't exist
called from user defined function Mysql:query
But it's more that its a stupid thing to do - ask an empty table for data - than a bug...

Posted: Fri Jan 30, 2009 8:47 pm
by Jeff
The problem is that you do not need to free the result after using :fetch-all. The final call to :fetch-row frees the result (I think that is in the documentation).

Posted: Sun Apr 05, 2009 1:11 am
by itistoday
This is a neat and useful module, I may end up using/testing it for a project... Thanks for writing it!