Mysql module

Notices and updates
Locked
Jeff
Posts: 604
Joined: Sat Apr 07, 2007 2:23 pm
Location: Ohio
Contact:

Mysql module

Post 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/
Jeff
=====
Old programmers don't die. They just parse on...

Artful code

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

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

Jeff
Posts: 604
Joined: Sat Apr 07, 2007 2:23 pm
Location: Ohio
Contact:

Post 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.
Jeff
=====
Old programmers don't die. They just parse on...

Artful code

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

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

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post 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)

Jeff
Posts: 604
Joined: Sat Apr 07, 2007 2:23 pm
Location: Ohio
Contact:

Post by Jeff »

The client library should work independent of the server's minor version.
Jeff
=====
Old programmers don't die. They just parse on...

Artful code

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

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

Jeff
Posts: 604
Joined: Sat Apr 07, 2007 2:23 pm
Location: Ohio
Contact:

Post 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.
Jeff
=====
Old programmers don't die. They just parse on...

Artful code

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

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

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

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

Jeff
Posts: 604
Joined: Sat Apr 07, 2007 2:23 pm
Location: Ohio
Contact:

Post by Jeff »

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

Artful code

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

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

Jeff
Posts: 604
Joined: Sat Apr 07, 2007 2:23 pm
Location: Ohio
Contact:

Post by Jeff »

Can you post the code you wrote that lead to that error?
Jeff
=====
Old programmers don't die. They just parse on...

Artful code

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

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

Jeff
Posts: 604
Joined: Sat Apr 07, 2007 2:23 pm
Location: Ohio
Contact:

Post 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).
Jeff
=====
Old programmers don't die. They just parse on...

Artful code

itistoday
Posts: 429
Joined: Sun Dec 02, 2007 5:10 pm
Contact:

Post by itistoday »

This is a neat and useful module, I may end up using/testing it for a project... Thanks for writing it!
Get your Objective newLISP groove on.

Locked