Mysql module

Started by Jeff, January 22, 2009, 09:37:22 AM

Previous topic - Next topic

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-better-mysql-module-for-newlisp/">http://www.artfulcode.net/articles/a-be ... r-newlisp/">http://www.artfulcode.net/articles/a-better-mysql-module-for-newlisp/
Jeff

=====

Old programmers don\'t die. They just parse on...



http://artfulcode.net\">Artful code

cormullion

#1
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...

Jeff

#2
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.
Jeff

=====

Old programmers don\'t die. They just parse on...



http://artfulcode.net\">Artful code

cormullion

#3
Well, I got this far:


QuoteERR: problem loading library in function import : "dlopen(/usr/local/mysql/lib/libmysqlclient.dylib, 9): no suitable image found.  Did find:nt/usr/local/mysql/lib/libmysqlclient.dylib: mach-o, but wrong architecture"


I think I did install it OK, though, because in the Terminal:


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...!:)

Lutz

#4
May be one of these:



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



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

Jeff

#5
The client library should work independent of the server's minor version.
Jeff

=====

Old programmers don\'t die. They just parse on...



http://artfulcode.net\">Artful code

cormullion

#6
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... :(

Jeff

#7
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.
Jeff

=====

Old programmers don\'t die. They just parse on...



http://artfulcode.net\">Artful code

Lutz

#8
Follow these instructions:



http://www.newlisp.org/downloads/MacOSX-MySQL/MySQL-5.1.3-install.txt">http://www.newlisp.org/downloads/MacOSX ... nstall.txt">http://www.newlisp.org/downloads/MacOSX-MySQL/MySQL-5.1.3-install.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.

cormullion

#9
Jeff, I noticed these weird lines in http://static.artfulcode.net/newlisp/mysql.lsp.src.html">//http://static.artfulcode.net/newlisp/mysql.lsp.src.html


("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... :)

Jeff

#10
Corm,



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

=====

Old programmers don\'t die. They just parse on...



http://artfulcode.net\">Artful code

cormullion

#11
I know this isn't a real bug, but if you run the example code on an empty table, you get this:


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:


(: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! :)

Jeff

#12
Can you post the code you wrote that lead to that error?
Jeff

=====

Old programmers don\'t die. They just parse on...



http://artfulcode.net\">Artful code

cormullion

#13
after creating a table t3 in mysql command line:


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

mysql>


i ran this in newlisp:


(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:


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:


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...

Jeff

#14
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).
Jeff

=====

Old programmers don\'t die. They just parse on...



http://artfulcode.net\">Artful code