From 3f5ee806075e9c68862fd6cba2650b969511c916 Mon Sep 17 00:00:00 2001 From: Arno Date: Sat, 2 Apr 2016 11:42:36 +0200 Subject: Reconnect to database after network failure It's more difficult than I thought. It seems you need a failed query until libpq notices that the connection is lost. Implement reconnect at the very bottom of the slide time to get it back as soon as possible. I have no idea though what it does to cloned connections. Also, if no slide show is running, it'll never reconnect. It works when I down the database, maybe create a Helper function for this... --- picfilesmodel.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/picfilesmodel.cpp b/picfilesmodel.cpp index 8ea4442..f0d02dc 100644 --- a/picfilesmodel.cpp +++ b/picfilesmodel.cpp @@ -172,9 +172,6 @@ SmTreeItem *PicFilesModel::mappingTreeFromFile(int fileId){ return 0; } SmTreeItem *retval = new SmTreeItem(2); - if(!mDb.isOpen()){ - mDb.open(); - } QSqlQuery mpq(mDb); mpq.prepare("SELECT imapping_parents_id, iparent_id, tdescription_name, mapping_parents.idescription_id FROM mapping_parents, mapping_description WHERE imapping_parents_id = :id AND mapping_parents.idescription_id = mapping_description.idescription_id"); foreach(int pId, parentIds){ @@ -295,8 +292,14 @@ QList PicFilesModel::mappingPIdsFromFiles(QList fileIds){ foreach(int id, fileIds){ idList << QString::number(id); } - QString query = mMappingsQS.arg(idList.join(",")); - QSqlQuery q(query, mDb); + QString qTempl = QString(mMappingsQS.arg(idList.join(","))); + QSqlQuery q(mDb); + q.prepare(qTempl); + if(!q.exec()){ + mDb.close(); + mDb.open(); + return QList(); + } QList retval; while(q.next()){ retval << q.value(0).toInt(); -- cgit v1.2.3-70-g09d2