LeechCraft 0.6.70-16373-g319c272718
Modular cross-platform feature rich live environment.
Loading...
Searching...
No Matches
dblock.h
Go to the documentation of this file.
1/**********************************************************************
2 * LeechCraft - modular cross-platform feature rich internet client.
3 * Copyright (C) 2006-2014 Georg Rudoy
4 *
5 * Distributed under the Boost Software License, Version 1.0.
6 * (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7 **********************************************************************/
8
9#pragma once
10
11#include <QMutex>
12#include <QString>
13#include <QSet>
14#include "dbconfig.h"
15
16class QSqlError;
17class QSqlQuery;
18class QSqlDatabase;
19
20namespace LC
21{
22namespace Util
23{
41 class DBLock
42 {
43 QSqlDatabase& Database_;
44
45 bool Good_ = false;
46 bool Initialized_ = false;
47
48 static QMutex LockedMutex_;
49 static QSet<QString> LockedBases_;
50 public:
51 DBLock (const DBLock&) = delete;
52 DBLock& operator= (const DBLock&) = delete;
53
54 DBLock (DBLock&&) = default;
55
65 UTIL_DB_API explicit DBLock (QSqlDatabase& database);
66
73
81 UTIL_DB_API void Init ();
82
89 UTIL_DB_API void Good ();
90
95 UTIL_DB_API static void DumpError (const QSqlError& error);
96
101 UTIL_DB_API static void DumpError (const QSqlQuery& query);
102
111 UTIL_DB_API static void Execute (QSqlQuery& query);
112 };
113};
114};
Provides database transaction lock.
Definition dblock.h:42
DBLock(const DBLock &)=delete
static UTIL_DB_API void Execute(QSqlQuery &query)
Tries to execute the given query.
Definition dblock.cpp:85
UTIL_DB_API void Init()
Initializes the transaction.
Definition dblock.cpp:45
DBLock & operator=(const DBLock &)=delete
UTIL_DB_API ~DBLock()
Destructor.
Definition dblock.cpp:29
UTIL_DB_API void Good()
Notifies the lock about successful higher-level operations.
Definition dblock.cpp:63
static UTIL_DB_API void DumpError(const QSqlError &error)
Dumps the error to the qWarning() stream.
Definition dblock.cpp:68
DBLock(DBLock &&)=default
#define UTIL_DB_API
Definition dbconfig.h:16
Definition constants.h:15