blob: 21560cbb9253ad1e0ad021d62b725a99bda0146c (
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
34
35
36
37
38
|
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
#pragma once
#include "sqlitedatabase.h"
namespace Sqlite {
class ProgressHandler
{
public:
template<typename Callable>
ProgressHandler(Callable &&callable,
int operationCount,
Database &database,
const source_location &sourceLocation = source_location::current())
: m_database{database}
, m_sourceLocation{sourceLocation}
{
std::unique_lock<TransactionInterface> locker{m_database};
m_database.backend().setProgressHandler(operationCount,
std::forward<Callable>(callable),
sourceLocation);
}
~ProgressHandler()
{
std::unique_lock<TransactionInterface> locker{m_database};
m_database.backend().resetProgressHandler(m_sourceLocation);
}
private:
Database &m_database;
source_location m_sourceLocation;
};
} // namespace Sqlite
|