summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBill King <bill.king@nokia.com>2009-09-22 01:38:02 (GMT)
committerBill King <bill.king@nokia.com>2009-09-22 01:38:02 (GMT)
commit21a71222c30214635cb369bedad43bc1e72f05be (patch)
tree75272759cd389a9d6762a707e14a1d3b909dae0c /src
parent69643cbd2a219d7e47ddeecc8d617a8c4c866552 (diff)
downloadQt-21a71222c30214635cb369bedad43bc1e72f05be.zip
Qt-21a71222c30214635cb369bedad43bc1e72f05be.tar.gz
Qt-21a71222c30214635cb369bedad43bc1e72f05be.tar.bz2
Add reconnection option to the mysql driver.
adds MYSQL_OPT_RECONNECT to the mysql driver options. Task-number: QTBUG-4510
Diffstat (limited to 'src')
-rw-r--r--src/sql/drivers/mysql/qsql_mysql.cpp13
-rw-r--r--src/sql/kernel/qsqldatabase.cpp1
2 files changed, 14 insertions, 0 deletions
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