import, libmysqlclient problems

Started by Jeff, June 02, 2009, 07:50:51 AM

Previous topic - Next topic

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:


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



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

Jeff

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


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



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