I normally develop with a live server, but for the first time I figured I'd make the leap and see if I could get all my (C++) mysql code working as an embedded server. Particularly, I'm very fond of prepared statements as they are (IMHO) "generally" superior to the non-prepared variety.
I've tried using libmysqld from 5.5.22 and libmysqld from 5.6.4 and neither work.
Connection is made, simple mysql_query / mysql_real_query commands work fine, but as soon as my first prepared statement issues a mysql_stmt_fetch() I get the hated 'commands out of sync' error.
A very similar issue appeard on oracles forums ( http://forums.mysql.com/read.php?168,507863,507863#msg-507863 ) without resolution.
I do not see, nor believe that I'm missing any commands between mysql_real_connect() and the mysql_stmt_fetch().
All my searches have come up empty for any example of an embedded server that is using prepared statements. Nor have I found an actual sentence "you can't do this".
So...is it or is it not supported?
Thank you for your expertise.
//edit so as to demystify this further (and instruct if necessary) my full mysql cmd sequence is as follows:
mysql_library_init(); // as embedded
mysql_init();
mysql_options(MYSQL_SET_CHARSET_NAME); //to utf8
mysql_options(MYSQL_OPT_USE_EMBEDDED_CONNECTION);
mysql_real_connect();
mysql_real_query("SET NAMES 'utf8'");
mysql_real_query("SET CHARACTER SET 'utf8'");
mysql_set_character_set("utf8"); // yes, you really do need to set utf8 four times
mysql_autocommit( mAutocommit );
at this point, mysql_real_query() calls DO work. I continue...
//all this would only happen once for each stmt
{
mysql_stmt_init();
mysql_stmt_prepare(theQuery);
mysql_stmt_param_count(); // to assert input bind object (aka the predicates) has the same number of params as theQuery
mysql_stmt_result_metadata()
mysql_num_fields(); // to assert the output bind object has the same number of params as theQuery
mysql_free_result(metadata);
mysql_stmt_bind_param(); // called IF there are input params
mysql_stmt_bind_result(); // pretty much always called for the output params
}
// and at last
mysql_stmt_execute();
//mysql_stmt_store_result(); //{OPTIONAL: use if you want to buffer the fetch - I dont}
mysql_stmt_fetch(); // ERROR! commands out of sync.
// and for completeness,
mysql_stmt_free_result();
mysql_stmt_close();
// and the shutdown
mysql_close();
mysql_library_end();