Prepared statements - commands out of sync
Posted by: Dominikus Heinzeller
Date: January 05, 2012 11:04PM

Hi,

I am having a problem that drives me nuts and I hope that someone can help me. I have the following sequence of code in C/C++:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

// db is a valid pointer to a database
MYSQL* conn = db->getConnection();

MYSQL_STMT* stmt = mysql_stmt_init(conn);

// sql is a valid mysql statement
mysql_stmt_prepare(stmt, sql.c_str(), sql.length());

// bindVariables are all defined properly
mysql_stmt_bind_param(stmt, bindVariables);

my_bool getMaxLength = true;
mysql_stmt_attr_set(stmt, STMT_ATTR_UPDATE_MAX_LENGTH, &getMaxLength);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

So far, so good. If I am now calling

if (mysql_stmt_store_result(stmt))
{
LOG_ERROR("Failed to store the query results to the client. "<< mysql_stmt_error(stmt));
return false;
}

I get an error with mysql_stmt_error(stmt)="Commands out of sync; you can't run this command now"

This happens ONLY when I am using the embedded server of mysql-5.5.16. If I am using an older version of the embedded server of mysql-5.0.21, everything works fine.

According to the documentation, the above sequence is the correct way to use prepared statements when the size of the query result is not known a priori:

http://dev.mysql.com/doc/refman/5.5/en/mysql-stmt-fetch.html

Can anyone help, pleasehttp://dev.mysql.com/doc/refman/5.5/en/mysql-stmt-fetch.html

Any ideas? Thanks a lot.

Dominikus

Options: ReplyQuote


Subject
Views
Written By
Posted
Prepared statements - commands out of sync
5204
January 05, 2012 11:04PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.