Mysql.mysql.set_charset does not trig error when connected to old mysql server
Imported from http://bugzilla.roxen.com/bugzilla/show_bug.cgi?id=6155
Reported by Martin Stjernholm mast@roxen.com
When connected to an old mysql server without charset support, Mysql.mysql.set_charset does not throw an error as it should. Instead the error occurs in the query afterwards, where it often won't be caught properly:
Pike v7.8 release 613 running Hilfe v3.5 (Incremental Pike Frontend)
> object o=Sql.Sql ("mysql://rw@megalon.roxen.com:4852/autodoc");
> o->set_charset("unicode");
(1) Result: 0
> o->query ("select 'apa'");
big_query(): Query "SET character_set_client=latin1" failed (Unknown system variable 'character_set_client')
/home/mast/Pike/stable/build/linux-x86_64/lib/modules/Mysql.so:1: mysql(/*megalon.roxen.com via TCP/IP*/)->big_query("SET character_set_client=latin1")
/home/mast/Pike/stable/lib/modules/Sql.pmod/mysql.pike:778: mysql(/*megalon.roxen.com via TCP/IP*/)->big_query("select 'apa'",UNDEFINED,UNDEFINED)
/home/mast/Pike/stable/lib/modules/Sql.pmod/Sql.pike:648: Sql.mysql(/*megalon.roxen.com via TCP/IP*/)->query("select 'apa'")
This only occurs when pike has been compiled with a mysql client lib new enough to contain mysql_set_character_set, so the problem is that that function doesn't trig an error. The doc isn't clear, but it can arguably be interpreted that an error should occur:
This function works like the SET NAMES statement, but also sets the value of mysql->charset, and thus affects the character set used by mysql_real_escape_string()
Return Values
Zero for success. Nonzero if an error occurred.
The db server in question does not support SET NAMES.