For the past few weeks I've been trying to use apr_dbd. The database I
want to use is MySQL (v. 5.0.41 currently). I successfully installed
apr_dbd_mysql.c (can't find any version on that one) into apr-util-1.2.8
on Fedora Core 6.
I obviously started with the simplest test case:
SELECT field FROM table
First I tried a prepared statement. This segfaulted on an iconv routine
somewhere deep in the libs. Thinking to go simpler, I tried a very
simple apr_dbd_select approach. Although apr_dbd_select does not return
any errors, apr_dbd_get_row is segfaulting, inside mysql code.
First I taught I have a version issue and tried a slew of different
MySQL versions, recompiling apr-util with each version, just to be sure.
Same result.
Using gdb and trying to track down the problem, this is as close as I
came to the culprit: somehow, a second thread seems to execute the same
mysql_query(...).
The first execution of ret = mysql_query(sql->conn, query) returns with
an error for ret=7740576 and immediately the statement is reexecuted
with an ret=0.
The resulting "results" struct exists, but it's fields are NULL (on the
second execution). No error is therefore returned to the calling program.
Once we call apr_dbd_get_row with this results field, a call is made to
r = mysql_fetch_row(res->res);
which segfaults inside mysql routines. Ok, mysql should catch that and
not segfault, but it's making the assumption that res is valid.
My issue is why is mysql_query being called twice. Is it related to
mysql being in threaded mode? Has ANYBODY successfully used
apr_dbd_mysql with version 5 in a non httpd setting, using only apr and
apr-util?
Any help or hint would be appreciated. I can post the simple code if
that helps - or the gdb trace. It's mostly housekeeping and error
checking, with a few lines of actual code.
Jacques Amar