import, libmysqlclient problems

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

import, libmysqlclient problems

Post by Jeff »

After upgrading to OSX 10.5, I am having some problems with imported functions from libmysqlclient. Many functions that return my_ulonglong are all returning 0. Other applications using the same libmysqlclient and importing the same functions work fine, and a short program I wrote in C using the library confirms that it is returning the correct values.

This happens in newlisp 10.2 and the development version. I have tried both versions using the compiled binary as well as compiling myself (darwin/utf8/readline). It happens with all of them.

Here is the sample code:

Code: Select all

(constant 'libmysqlclient "/usr/local/mysql/lib/libmysqlclient.dylib")

(import libmysqlclient "mysql_init")
(import libmysqlclient "mysql_real_connect")
(import libmysqlclient "mysql_real_query")
(import libmysqlclient "mysql_store_result")
(import libmysqlclient "mysql_free_result")
(import libmysqlclient "mysql_close")
(import libmysqlclient "mysql_num_rows")
(import libmysqlclient "mysql_field_count")

(setf sql "select * from some_table_with_lots_of_records")

(setf MYSQL (mysql_init 0))
(println "Connecting: "		(mysql_real_connect MYSQL "localhost" "user" "secret" "db" 0 0 0))
(println "Querying: "			(mysql_real_query MYSQL sql (+ 1 (length sql))))
(println "Storing: "			(setf MYSQL_RES (mysql_store_result MYSQL)))
;; !!! This should return a number in the thousands, but always returns 0.
(println "Rows found: "		(mysql_num_rows MYSQL_RES))
(println "Freeing: "			(mysql_free_result MYSQL_RES))
(println "Cleaning up: "	(mysql_close MYSQL))
(exit 0)
mysql_affected_rows is also behaving similarly.

I tried recompiling mysql after the upgrade, and using the new library, I get the same results.

Does anyone have *any* idea what might be happening?
Jeff
=====
Old programmers don't die. They just parse on...

Artful code

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

Post by Jeff »

I found the problem, and this affects both my mysql module and yours, Lutz. mysql_num_rows requires the address of MYSQL_RES, and returns a 64-bit ulong, which must be unpacked. This works:

Code: Select all

(first (unpack "Lu" (mysql_num_rows (address MYSQL_RES))))
Can anyone test that on 10.4? Or any other platforms?
Jeff
=====
Old programmers don't die. They just parse on...

Artful code

Post Reply