diff options
author | Arno <arno@disconnect.de> | 2016-04-02 11:42:36 +0200 |
---|---|---|
committer | Arno <arno@disconnect.de> | 2016-04-02 11:42:36 +0200 |
commit | 3f5ee806075e9c68862fd6cba2650b969511c916 (patch) | |
tree | efbefa15ea1b37177fdf2c7a2ad6dcf2116ee149 /picfilesmodel.cpp | |
parent | e683eb842e1db846b05ed4261c839e62862e3c70 (diff) | |
download | SheMov-3f5ee806075e9c68862fd6cba2650b969511c916.tar.gz SheMov-3f5ee806075e9c68862fd6cba2650b969511c916.tar.bz2 SheMov-3f5ee806075e9c68862fd6cba2650b969511c916.zip |
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...
Diffstat (limited to 'picfilesmodel.cpp')
-rw-r--r-- | picfilesmodel.cpp | 13 |
1 files 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<int> PicFilesModel::mappingPIdsFromFiles(QList<int> 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<int>(); + } QList<int> retval; while(q.next()){ retval << q.value(0).toInt(); |