mirror of
https://github.com/fralx/LimeReport.git
synced 2024-12-24 16:44:39 +03:00
Connection will be restored if server is gone away or drop limereport connection
This commit is contained in:
parent
f613400839
commit
034f254d5c
@ -702,12 +702,17 @@ bool DataSourceManager::initAndOpenDB(QSqlDatabase& db, ConnectionDesc& connecti
|
|||||||
return connected;
|
return connected;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool DataSourceManager::checkConnection(QSqlDatabase& db){
|
||||||
|
QSqlQuery query("Select 1",db);
|
||||||
|
return query.first();
|
||||||
|
}
|
||||||
|
|
||||||
bool DataSourceManager::connectConnection(ConnectionDesc *connectionDesc)
|
bool DataSourceManager::connectConnection(ConnectionDesc *connectionDesc)
|
||||||
{
|
{
|
||||||
|
|
||||||
bool connected = false;
|
bool connected = false;
|
||||||
clearErrors();
|
clearErrors();
|
||||||
QString lastError ="";
|
QString lastError = "";
|
||||||
|
|
||||||
foreach(QString datasourceName, dataSourceNames()){
|
foreach(QString datasourceName, dataSourceNames()){
|
||||||
dataSourceHolder(datasourceName)->clearErrors();
|
dataSourceHolder(datasourceName)->clearErrors();
|
||||||
@ -715,7 +720,7 @@ bool DataSourceManager::connectConnection(ConnectionDesc *connectionDesc)
|
|||||||
|
|
||||||
if (!QSqlDatabase::contains(connectionDesc->name())){
|
if (!QSqlDatabase::contains(connectionDesc->name())){
|
||||||
QSqlDatabase db = QSqlDatabase::addDatabase(connectionDesc->driver(),connectionDesc->name());
|
QSqlDatabase db = QSqlDatabase::addDatabase(connectionDesc->driver(),connectionDesc->name());
|
||||||
connected=initAndOpenDB(db, *connectionDesc);
|
connected = initAndOpenDB(db, *connectionDesc);
|
||||||
if (!connected){
|
if (!connected){
|
||||||
setLastError(db.lastError().text());
|
setLastError(db.lastError().text());
|
||||||
return false;
|
return false;
|
||||||
@ -726,7 +731,10 @@ bool DataSourceManager::connectConnection(ConnectionDesc *connectionDesc)
|
|||||||
db.close();
|
db.close();
|
||||||
connected = initAndOpenDB(db, *connectionDesc);
|
connected = initAndOpenDB(db, *connectionDesc);
|
||||||
} else {
|
} else {
|
||||||
connected = db.isOpen();
|
// connected = db.isOpen();
|
||||||
|
connected = checkConnection(db);
|
||||||
|
if (!connected)
|
||||||
|
connected = initAndOpenDB(db, *connectionDesc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,6 +215,7 @@ protected:
|
|||||||
void setLastError(const QString& value);
|
void setLastError(const QString& value);
|
||||||
void invalidateLinkedDatasources(QString datasourceName);
|
void invalidateLinkedDatasources(QString datasourceName);
|
||||||
|
|
||||||
|
bool checkConnection(QSqlDatabase &db);
|
||||||
private slots:
|
private slots:
|
||||||
void slotConnectionRenamed(const QString& oldName,const QString& newName);
|
void slotConnectionRenamed(const QString& oldName,const QString& newName);
|
||||||
void slotQueryTextChanged(const QString& queryName, const QString& queryText);
|
void slotQueryTextChanged(const QString& queryName, const QString& queryText);
|
||||||
|
Loading…
Reference in New Issue
Block a user