Comment #1 on issue 402 by uale...@gmail.com: String charset is screwed up if the MySQL connection is temporary lost http://code.google.com/p/gambas/issues/detail?id=402
@Benoit: Ok, i know how to fix the problem. First why it happens in gambas: - When gambas opens the connection, it does a "set names 'utf8'" to set the characterset. - gambas also sets the option to automatically reconnect "MYSQL_OPT_RECONNECT" - Only if a reconnect happens, the "set names 'utf8'" setting on this connection is gone The fix is in the file "gb.db.mysql/src/main.c" as follows in the function: static int do_query(DB_DATABASE *db, const char *error, MYSQL_RES **pres, const char *qtemp, int nsubst, ...) Add the following lines: unsigned long thread_id; thread_id = mysql_thread_id(conn); mysql_ping(conn); if ( mysql_thread_id(conn) != thread_id ) { // Connection has been reestablished, set utf8 again mysql_query(conn, "set names 'utf8'"); } Just before the "real query": if(mysql_query(conn, query)){ This fixes the problem nicely :-):-):-) Reference info: http://dev.mysql.com/doc/refman/5.0/en/auto-reconnect.html http://dev.mysql.com/doc/refman/5.0/en/mysql-ping.html http://dev.mysql.com/doc/refman/5.0/en/mysql-thread-id.html Can this fix (or improved by you) be included into gambas? Else people using none us-ascii character can see weird characters if a reconnect happens with MySQL. ------------------------------------------------------------------------------ Free Next-Gen Firewall Hardware Offer Buy your Sophos next-gen firewall before the end March 2013 and get the hardware for free! Learn more. http://p.sf.net/sfu/sophos-d2d-feb _______________________________________________ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user