[Gambas-user] Issue 402 in gambas: String charset is screwed up if the MySQL connection is temporary lost
gambas at ...2524...
gambas at ...2524...
Thu Feb 7 05:29:22 CET 2013
Comment #1 on issue 402 by uAle... at ...626...: 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.
More information about the User
mailing list