blob: a6fc06902cc83cd835b074cf85e0443f113c4f39 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
#pragma once
#include <QSqlQuery>
// 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)
}
SqlQueryFinisher(SqlQueryFinisher&& other)
: m_query(std::move(other.m_query)) { // implicitly shared (not moved)
other.release();
}
~SqlQueryFinisher() {
finish();
}
bool finish();
void release();
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
};
|