Bug #17732 ignoring 'options' in Connection object without any explanation
Submitted: 27 Feb 2006 1:13 Modified: 28 Feb 2006 16:08
Reporter: [ name withheld ] Email Updates:
Status: Won't fix Impact on me:
None 
Category:MySQL++ Severity:S3 (Non-critical)
Version:mysql++-2.0.7.tar.gz OS:irrelevant
Assigned to: CPU Architecture:Any

[27 Feb 2006 1:13] [ name withheld ]
Description:
In my program I had to use the Connection.set_option() method 
(in my case it was the 'opt_set_charset_name' with arg "char1250" but I think it's irrelevant). 

To my surprise the program behaved like it ignored this option, because data I received from remote dbserver was wrong (special characters in latin2 encoding weren't encoded into cp1250).

I setup a sniffer to make sure that it's the server that sends wrong data.

Then I created a sample program in pure mysql C api and it worked (with mysql_options())

I debugged mysqlpp.lib and dll and everything seemed the same between C and C++ api but there was one difference. In my C program, option was setup BEFORE calling mysql_real_connect, whereas in the mysqlc++ library it is setup AFTER the call.

I changed the source of mysql++ (Connection.cpp) so now 	apply_pending_options() was called BEFORE mysql_real_connect and then everything worked ok.

I'm not sure whether this counts as a MySQL++ bug or it's also a mistake in MySQL C API documentation that the importance of precedence of these function calls is not clearly stated.

How to repeat:
		enum mysqlpp::Connection::Option opcja = mysqlpp::Connection::Option::opt_set_charset_name;
				
		mysqlpp::Connection* c  = new Connection();
		
		bool czek = c->set_option(opcja, "cp1250");
//this gives us false because 'opcja' is enqueued to be included on connect()

		c->connect("somedb", "somewhere", "someuser, "somepassword");
	
st_mysql_options a = c->get_options();
//this gives theoretically proper results (that option is changed), but in fact it doesn't show you what's really going on

		Query qqq = c->query();
		
		qqq << "some select in a dbase with special latin2 character that you want convert to cp1250 for example";

		Result rrr = qqq.store();				
		
		string s1 = rrr.at(0)["some column with some special latin2 character in it"];

Suggested fix:
in connection.cpp for mysql++ library in code for all connect() functions change the fragment from: 

	// Establish connection
	if (mysql_real_connect(&mysql_, host, user, passwd, db, port,
			socket_name, client_flag)) {
		unlock();
		success_ = is_connected_ = true;
                apply_pending_options(); 

to :

	apply_pending_options(); //DONE BY VOLT

	// Establish connection
	if (mysql_real_connect(&mysql_, host, user, passwd, db, port,
			socket_name, client_flag)) {
		unlock();
		success_ = is_connected_ = true;

It worked for me, I don't know if it is the miracle cure for all cases.
[28 Feb 2006 16:08] Valeriy Kravchuk
Thank you for a problem report. Sorry, but MySQL++ is not really supported now. So, I am not sure this bug, if any, will ever be fixed.
[28 Feb 2006 16:11] Valeriy Kravchuk
The code is now maintained by Warren Young from the community. Use the appropriate mailing list.