From 8659818a30bb5c3a54fc6d5601201ac1bba0646c Mon Sep 17 00:00:00 2001 From: Arin Alexander Date: Sat, 11 Feb 2017 00:24:59 +0300 Subject: [PATCH] Connection will be restored if server is gone away or drop limereport connection --- limereport/lrdatasourcemanager.cpp | 10 +++++++++- limereport/lrdatasourcemanager.h | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/limereport/lrdatasourcemanager.cpp b/limereport/lrdatasourcemanager.cpp index bab241d..2fb0d40 100644 --- a/limereport/lrdatasourcemanager.cpp +++ b/limereport/lrdatasourcemanager.cpp @@ -735,6 +735,11 @@ void DataSourceManager::setReportSettings(ReportSettings *reportSettings) m_reportSettings = reportSettings; } +bool DataSourceManager::checkConnection(QSqlDatabase db){ + QSqlQuery query("Select 1",db); + return query.first(); +} + bool DataSourceManager::connectConnection(ConnectionDesc *connectionDesc) { @@ -759,7 +764,10 @@ bool DataSourceManager::connectConnection(ConnectionDesc *connectionDesc) db.close(); connected = initAndOpenDB(db, *connectionDesc); } else { - connected = db.isOpen(); + //connected = db.isOpen(); + connected = checkConnection(db); + if (!connected) + connected = initAndOpenDB(db, *connectionDesc); } } diff --git a/limereport/lrdatasourcemanager.h b/limereport/lrdatasourcemanager.h index 7670b2e..a0efaaf 100644 --- a/limereport/lrdatasourcemanager.h +++ b/limereport/lrdatasourcemanager.h @@ -221,7 +221,7 @@ protected: void setSystemVariable(const QString& name, const QVariant& value, RenderPass pass); void setLastError(const QString& value); void invalidateLinkedDatasources(QString datasourceName); - + bool checkConnection(QSqlDatabase db); private slots: void slotConnectionRenamed(const QString& oldName,const QString& newName); void slotQueryTextChanged(const QString& queryName, const QString& queryText);