Hi
I'm facing a strange issue in my client application using MySQL c++ connector .
I searched a lot about this but I didn't find any useful informations. Most of the post are dedicated to C API or unsolved.
I have write some stored procedure and everything is just fine when running them from the mysql prompt.
However when calling them from the c++ client shit happens.
I need to call the same SP multiple times, the first call is ok and ran just fine but the other throw the following exception : Commands out of sync; you can't run this command now.
I obviously have no idea about the way to solve this. My guess is that some of the objects are not completely closed/destroyed.
Here is the code fragment causing me troubles :
################################
for(int i=0; i < 3; i++) {
sql::PreparedStatement* p_statement = NULL;
sql::ResultSet* p_result_set = NULL;
try {
// Use a prepared statement to call the stored procedure
p_statement = p_connection->prepareStatement("CALL db.myproc(?, ?, ?)");
p_statement->setString(1, arg1);
p_statement->setString(2, arg2);
p_statement->setUInt(3, arg3);
p_result_set = p_statement->executeQuery();
p_result_set->first();
std::cout << p_result_set->getBoolean(1) << std::endl;
} catch (sql::SQLException& ex) {
std::cout << ex.what() << std::endl;
}
delete p_result_set;
delete p_statement;
}
################################
1) According to the doc (http://dev.mysql.com/doc/refman/5.5/en/connector-cpp-usage-notes.html) (Last list item) : The calling methode is ok. Right?
2) Any idea about what I'm doing wrong?
[EDIT]
Some news, apparently It seems needed to perform a call to mysql_next_result() when using callable statement. Obviously the corresponding method in the C++ (in the class PreparedStatement::getMoreResults) API isn't implemented ATM. So I suppose I have to work with simple statement instead. Not so good but it's already better than realloc a new connection. I will try and keep this post updated.
[EDIT 2]
Using a normal Statement works. However I loose the benefits of the prepared statement. Now I only hope that this feature will be implemented soon. This topic can be closed.
[EDIT 3]
For those who really need prepared statement + stored procedure ...
Against http://mysql-connector-cplus-pplus-p.sourcearchive.com/downloads/1.1.0~r814-1/
*** ./mysql_prepared_statement.cpp 2010-03-09 22:40:43.000000000 +0100
--- ../mysql_prepared_statement.cpp 2011-04-14 23:07:18.114377005 +0200
***************
*** 915,923 ****
bool
MySQL_Prepared_Statement::getMoreResults()
{
! checkClosed();
! throw MethodNotImplementedException("MySQL_Prepared_Statement::getMoreResults");
! return false; // fool compilers
}
/* }}} */
--- 915,935 ----
bool
MySQL_Prepared_Statement::getMoreResults()
{
! CPP_ENTER("MySQL_Statement::getMaxRows");
! CPP_INFO_FMT("this=%p", this);
! checkClosed();
! if (proxy->more_results()) {
! int next_result = proxy->next_result();
! if (next_result > 0) {
! CPP_ERR_FMT("Error during getMoreResults : %d:(%s) %s", proxy->errNo(), proxy->sqlstate().c_str(), proxy->error().c_str());
! sql::mysql::util::throwSQLException(*proxy.get());
! } else if (next_result == 0) {
! return proxy->field_count() != 0;
! } else if (next_result == -1) {
! throw sql::SQLException("Impossible! more_results() said true, next_result says no more results");
! }
! }
! return false;
}
/* }}} */
Working like a charm
____________________
A similar issue can be found here :
http://forums.mysql.com/read.php?167,386219,386219#msg-386219
____________________
mysql connector version : 1.1.0
mysqld Ver 5.5.11 for Linux on i686 (Source distribution)
I'm facing a strange issue in my client application using MySQL c++ connector .
I searched a lot about this but I didn't find any useful informations. Most of the post are dedicated to C API or unsolved.
I have write some stored procedure and everything is just fine when running them from the mysql prompt.
However when calling them from the c++ client shit happens.
I need to call the same SP multiple times, the first call is ok and ran just fine but the other throw the following exception : Commands out of sync; you can't run this command now.
I obviously have no idea about the way to solve this. My guess is that some of the objects are not completely closed/destroyed.
Here is the code fragment causing me troubles :
################################
for(int i=0; i < 3; i++) {
sql::PreparedStatement* p_statement = NULL;
sql::ResultSet* p_result_set = NULL;
try {
// Use a prepared statement to call the stored procedure
p_statement = p_connection->prepareStatement("CALL db.myproc(?, ?, ?)");
p_statement->setString(1, arg1);
p_statement->setString(2, arg2);
p_statement->setUInt(3, arg3);
p_result_set = p_statement->executeQuery();
p_result_set->first();
std::cout << p_result_set->getBoolean(1) << std::endl;
} catch (sql::SQLException& ex) {
std::cout << ex.what() << std::endl;
}
delete p_result_set;
delete p_statement;
}
################################
1) According to the doc (http://dev.mysql.com/doc/refman/5.5/en/connector-cpp-usage-notes.html) (Last list item) : The calling methode is ok. Right?
2) Any idea about what I'm doing wrong?
[EDIT]
Some news, apparently It seems needed to perform a call to mysql_next_result() when using callable statement. Obviously the corresponding method in the C++ (in the class PreparedStatement::getMoreResults) API isn't implemented ATM. So I suppose I have to work with simple statement instead. Not so good but it's already better than realloc a new connection. I will try and keep this post updated.
[EDIT 2]
Using a normal Statement works. However I loose the benefits of the prepared statement. Now I only hope that this feature will be implemented soon. This topic can be closed.
[EDIT 3]
For those who really need prepared statement + stored procedure ...
Against http://mysql-connector-cplus-pplus-p.sourcearchive.com/downloads/1.1.0~r814-1/
*** ./mysql_prepared_statement.cpp 2010-03-09 22:40:43.000000000 +0100
--- ../mysql_prepared_statement.cpp 2011-04-14 23:07:18.114377005 +0200
***************
*** 915,923 ****
bool
MySQL_Prepared_Statement::getMoreResults()
{
! checkClosed();
! throw MethodNotImplementedException("MySQL_Prepared_Statement::getMoreResults");
! return false; // fool compilers
}
/* }}} */
--- 915,935 ----
bool
MySQL_Prepared_Statement::getMoreResults()
{
! CPP_ENTER("MySQL_Statement::getMaxRows");
! CPP_INFO_FMT("this=%p", this);
! checkClosed();
! if (proxy->more_results()) {
! int next_result = proxy->next_result();
! if (next_result > 0) {
! CPP_ERR_FMT("Error during getMoreResults : %d:(%s) %s", proxy->errNo(), proxy->sqlstate().c_str(), proxy->error().c_str());
! sql::mysql::util::throwSQLException(*proxy.get());
! } else if (next_result == 0) {
! return proxy->field_count() != 0;
! } else if (next_result == -1) {
! throw sql::SQLException("Impossible! more_results() said true, next_result says no more results");
! }
! }
! return false;
}
/* }}} */
Working like a charm
____________________
A similar issue can be found here :
http://forums.mysql.com/read.php?167,386219,386219#msg-386219
____________________
mysql connector version : 1.1.0
mysqld Ver 5.5.11 for Linux on i686 (Source distribution)