diff options
Diffstat (limited to 'src/util/db/sqlqueryfinisher.h')
-rw-r--r-- | src/util/db/sqlqueryfinisher.h | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/src/util/db/sqlqueryfinisher.h b/src/util/db/sqlqueryfinisher.h index a6fc06902c..8cc19087b8 100644 --- a/src/util/db/sqlqueryfinisher.h +++ b/src/util/db/sqlqueryfinisher.h @@ -2,32 +2,38 @@ #include <QSqlQuery> +#include "util/db/fwdsqlquery.h" -// Ensures that reusable queries are properly finished when -// leaving the corresponding execution scope. This will free -// resources of prepared statements until the next execution. +/// Ensures that reusable queries are properly finished when +/// leaving the corresponding execution scope. This will free +/// resources of prepared statements until the next execution. class SqlQueryFinisher final { -public: - explicit SqlQueryFinisher(const QSqlQuery& query) - : m_query(query) { // implicitly shared (not copied) - } + public: + explicit SqlQueryFinisher(QSqlQuery* pQuery) + : m_pQuery(pQuery) { + } + explicit SqlQueryFinisher(FwdSqlQuery* pQuery) + : m_pQuery(pQuery) { + } SqlQueryFinisher(SqlQueryFinisher&& other) - : m_query(std::move(other.m_query)) { // implicitly shared (not moved) - other.release(); + : m_pQuery(other.m_pQuery) { + other.m_pQuery = nullptr; } ~SqlQueryFinisher() { - finish(); + tryFinish(); } - bool finish(); + bool tryFinish(); - void release(); + void release() { + m_pQuery = nullptr; + } -private: + private: // Disable copy construction and copy/move assignment SqlQueryFinisher(const SqlQueryFinisher&) = delete; SqlQueryFinisher& operator=(const SqlQueryFinisher&) = delete; SqlQueryFinisher& operator=(SqlQueryFinisher&&) = delete; - QSqlQuery m_query; // implicitly shared + QSqlQuery* m_pQuery; }; |