Permalink
Browse files

Enable automatic reconnection for MySQL connections.

After 155138a changed the minimum supported Qt version to 4.6, we now
have support for MYSQL_OPT_RECONNECT in
QSqlDatabase::setConnectOptions().

Note that before MySQL 5, reconnecting connections were the default in
the MySQL C API (so, were always enabled for the Qt-MySQL driver).
Unfortunately, depending on how the application is written,
reconnections may cause issues (since reconnections have effects on
transactions, table locks, temporary tables, session and user variables,
prepared statements, and such), so MySQL 5.0.3 changed the default to
disable automatic reconnections, and MySQL 5.0.13 added
MYSQL_OPT_RECONNECT to make reconnection an application-controllable
option.  Since the Qt-MySQL driver didn't have support for specifying
MYSQL_OPT_RECONNECT, it was impossible to get reconnecting connections
with MySQL 5.0.3+ in Qt applications.  Finally in Qt4.6, Qt devs added
support for specifying MYSQL_OPT_RECONNECT, so we can re-enable
automatic reconnect.

Thanks to David Edwards for the reminder to set this option.

Refs #9704, #9773, #9792.
  • Loading branch information...
1 parent afbf58d commit dd2d7a14d10c55f8bc8d12e944adb3b3c9ac8cea @sphery sphery committed Jul 27, 2011
Showing with 3 additions and 0 deletions.
  1. +3 −0 mythtv/libs/libmythbase/mythdbcon.cpp
@@ -71,6 +71,9 @@ MSqlDatabase::MSqlDatabase(const QString &name)
LOG(VB_GENERAL, LOG_ERR, "Unable to init db connection.");
return;
}
+ QString connectOptions("MYSQL_OPT_RECONNECT=1");
+ LOG(VB_GENERAL, LOG_DEBUG, "Setting connect options: " + connectOptions);
+ m_db.setConnectOptions(connectOptions);
m_lastDBKick = QDateTime::currentDateTime().addSecs(-60);
}

0 comments on commit dd2d7a1

Please sign in to comment.