From 21a71222c30214635cb369bedad43bc1e72f05be Mon Sep 17 00:00:00 2001 From: Bill King Date: Tue, 22 Sep 2009 11:38:02 +1000 Subject: Add reconnection option to the mysql driver. adds MYSQL_OPT_RECONNECT to the mysql driver options. Task-number: QTBUG-4510 --- src/sql/drivers/mysql/qsql_mysql.cpp | 13 +++++++++++++ src/sql/kernel/qsqldatabase.cpp | 1 + 2 files changed, 14 insertions(+) diff --git a/src/sql/drivers/mysql/qsql_mysql.cpp b/src/sql/drivers/mysql/qsql_mysql.cpp index 10422ff..f368d1d 100644 --- a/src/sql/drivers/mysql/qsql_mysql.cpp +++ b/src/sql/drivers/mysql/qsql_mysql.cpp @@ -1213,6 +1213,9 @@ bool QMYSQLDriver::open(const QString& db, unsigned int optionFlags = Q_CLIENT_MULTI_STATEMENTS; const QStringList opts(connOpts.split(QLatin1Char(';'), QString::SkipEmptyParts)); QString unixSocket; +#if MYSQL_VERSION_ID >= 50000 + my_bool reconnect=false; +#endif // extract the real options from the string for (int i = 0; i < opts.count(); ++i) { @@ -1223,6 +1226,12 @@ bool QMYSQLDriver::open(const QString& db, QString opt = tmp.left(idx).simplified(); if (opt == QLatin1String("UNIX_SOCKET")) unixSocket = val; +#if MYSQL_VERSION_ID >= 50000 + else if (opt == QLatin1String("MYSQL_OPT_RECONNECT")) { + if (val == QLatin1String("TRUE") || val == QLatin1String("1") || val.isEmpty()) + reconnect = true; + } +#endif else if (val == QLatin1String("TRUE") || val == QLatin1String("1")) setOptionFlag(optionFlags, tmp.left(idx).simplified()); else @@ -1255,6 +1264,10 @@ bool QMYSQLDriver::open(const QString& db, setOpenError(true); return false; } +#if MYSQL_VERSION_ID >= 50000 + if(reconnect) + mysql_options(d->mysql, MYSQL_OPT_RECONNECT, &reconnect); +#endif } else { setLastError(qMakeError(tr("Unable to connect"), QSqlError::ConnectionError, d)); diff --git a/src/sql/kernel/qsqldatabase.cpp b/src/sql/kernel/qsqldatabase.cpp index 18a04a3..821760f 100644 --- a/src/sql/kernel/qsqldatabase.cpp +++ b/src/sql/kernel/qsqldatabase.cpp @@ -1228,6 +1228,7 @@ QSqlRecord QSqlDatabase::record(const QString& tablename) const \i CLIENT_NO_SCHEMA \i CLIENT_INTERACTIVE \i UNIX_SOCKET + \i MYSQL_OPT_RECONNECT \endlist \i -- cgit v0.12