You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modules-dev@httpd.apache.org by Andrej van der Zee <an...@gmail.com> on 2008/10/03 14:51:18 UTC
mod_dbd/apr_dbd and "Commands out of sync"
Hi,
I am using mod_dbd for the first time and get into trouble when I
execute the following in sequence:
1) do an INSERT
2) do a SELECT
3) do another INSERT
On 3) I get the error "Commands out of sync; you can't run this
command now". This is what MySQL sais:
"If you get Commands out of sync; you can't run this command now in
your client code, you are calling client functions in the wrong order.
This can happen, for example, if you are using mysql_use_result() and
try to execute a new query before you have called mysql_free_result().
It can also happen if you try to execute two queries that return data
without calling mysql_use_result() or mysql_store_result() in between.
"
I went through all the apr_dbd_XXX functions in
apr-util/include/apr_dbd.h but could not find any way to free a result
after 2). How should I deal with this issue?
Cheers,
Andrej
Re: mod_dbd/apr_dbd and "Commands out of sync"
Posted by Andrej van der Zee <an...@gmail.com>.
Hi,
I still have another open issue with mod_dbd I was hoping you could
help me with. When I execute the query "SELECT LAST_INSERT_ID()" I
always get an empty string as a result. I do receive one row, but
nothing in it. Is this a mod_dbd issue you think, or a mysql issue?
Cheers,
Andrej
Re: mod_dbd/apr_dbd and "Commands out of sync"
Posted by Andrej van der Zee <an...@gmail.com>.
Hi,
When I execute two SELECT statements after each other I do not get the
"Comamnd out of sync" error anymore if I iterate through all the rows
in the apr_dbd_results_t, but I do get all emty values and column
names for the 2nd SELECT.
>
> Can you please post your code ?
>
Below the code. The second SELECT has 5 rows all with empty fields.
Thanks alot!
Andrej
apr_dbd_results_t *dbd_results = NULL;
int dbd_rv;
char *stmt = (char*) apr_psprintf(r->pool, "SELECT request_type_id
FROM request_type WHERE name = '%s'", req_cfg->tid);
if (dbd_rv = apr_dbd_select(dbd->driver, r->pool, dbd->handle,
&dbd_results, stmt, 0)) {
const char *errmsg = apr_dbd_error(dbd->driver, dbd->handle, dbd_rv);
ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server, "Perfmon: Failed
to execute statement '%s': %s", stmt, errmsg);
return DECLINED;
}
apr_dbd_row_t *dbd_row = NULL;
const char *request_type_id = NULL;
for (rv = apr_dbd_get_row(dbd->driver, r->pool, dbd_results, &dbd_row, -1);
rv != -1;
rv = apr_dbd_get_row(dbd->driver, r->pool, dbd_results, &dbd_row, -1)) {
request_type_id = apr_dbd_get_entry(dbd->driver, dbd_row, 0);
}
apr_dbd_results_t *dbd_results2 = NULL;
apr_dbd_row_t *dbd_row2 = NULL;
if (dbd_rv = apr_dbd_select(dbd->driver, r->pool, dbd->handle,
&dbd_results2, "SELECT * FROM request_type", 0)) {
const char *errmsg = apr_dbd_error(dbd->driver, dbd->handle, dbd_rv);
ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server, "Perfmon: Failed
to execute statement '%s': %s", stmt, errmsg);
return DECLINED;
}
// Here I get all empty strings for the name!
ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server, "Perfmon: name col:
", apr_dbd_get_name(dbd->driver, dbd_results2, 0));
for (rv = apr_dbd_get_row(dbd->driver, r->pool, dbd_results2, &dbd_row2, -1);
rv != -1;
rv = apr_dbd_get_row(dbd->driver, r->pool, dbd_results2, &dbd_row2, -1)) {
const char *request_type_id = apr_dbd_get_entry(dbd->driver, dbd_row2, 0);
// Here I get 5 rows with an empty request_type_id!
ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server, "Perfmon: : ",
request_type_id);
}
Re: mod_dbd/apr_dbd and "Commands out of sync"
Posted by Andrej van der Zee <an...@gmail.com>.
Hi Jerome,
Thanks for your answer.
I just went through the sources of apr_dbd and saw that I have to loop
through all the rows in a apr_dbd_results_t before mysql_free_result()
is called through apr_pool_cleanup_run(). In my code I am sure the
result is exactly one, but unfortunately I have to write a loop
anyway.
Nevertheless, it works now...
Cheers,
Andrej
Re: mod_dbd/apr_dbd and "Commands out of sync"
Posted by Jérôme Renard <jr...@ez.no>.
Andrej van der Zee a écrit :
> Hi,
[...]
> "
>
> I went through all the apr_dbd_XXX functions in
> apr-util/include/apr_dbd.h but could not find any way to free a result
> after 2). How should I deal with this issue?
Can you please post your code ?
--
Jérôme :)