MySQL Forums
Forum List  »  Connector/C++

MySQL++ stored procedure usage
Posted by: Shawn halayka
Date: June 17, 2008 11:28AM

I'm trying to use MySQL++ with stored procedures on MySQL 5.0.45-community, but cannot get it to work properly.

My stored procedure is:

drop procedure if exists getTypes;
delimiter //
create procedure getTypes(IN _ID int(11), IN _password VARCHAR(50), OUT return_code int)
BEGIN
set return_code := 1; -- for now we will pretend that authentication was successful
if return_code = 1 then
select TypeID, TypeName from Type;
end if;
END
//
delimiter ;

This works fine when called from the MySQL commandline tool.

My C++ code is not working, giving a command out of sync error. I am not sure what I'm doing incorrectly:

// Connect to server
const char* db = "dbname", *server = "servername", *user = "username", *pass = "password";
mysqlpp::Connection conn(false);
conn.set_option(new mysqlpp::MultiResultsOption(true));
conn.connect(db, server, user, pass);

// Call stored procedure, get sole row set
mysqlpp::Query query = conn.query();
query << "call getTypes('0', 'password', @ret)";
mysqlpp::StoreQueryResult res = query.store();

// Not necessary since there is only one result set,
// but I'm trying everything to make this work
while(query.more_results())
res = query.store_next();

// Get return value placed into @ret
mysqlpp::Query query2 = conn.query("select @ret");
query2 << "select @ret";
mysqlpp::StoreQueryResult res2;

// This is where the error occurs
if(0 == (res2 = query2.store()))
{
cout << "err: " << query2.error() << endl;
}

The error is prints here is:

err: Commands out of sync; you can't run this command now

Any help is greatly appreciated!

Options: ReplyQuote


Subject
Views
Written By
Posted
MySQL++ stored procedure usage
8478
June 17, 2008 11:28AM


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.