32 #include <QSqlDatabase>
35 #include <QMutexLocker>
38 QSet<QString> LeechCraft::Util::DBLock::LockedBases_;
39 QMutex LeechCraft::Util::DBLock::LockedMutex_;
42 : Database_ (database)
44 , Initialized_ (false)
53 if (Good_ ? !Database_.commit () : !Database_.rollback ())
54 DumpError (Database_.lastError ());
57 QMutexLocker locker (&LockedMutex_);
58 LockedBases_.remove (Database_.connectionName ());
65 QMutexLocker locker (&LockedMutex_);
66 const auto& conn = Database_.connectionName ();
67 if (LockedBases_.contains (conn))
72 if (!Database_.transaction ())
74 DumpError (Database_.lastError ());
75 throw std::runtime_error (
"Could not start transaction");
87 qWarning () << lastError.text () <<
"|"
88 << lastError.type () <<
"|"
89 << lastError.number ();
94 qWarning () << lastQuery.lastQuery ();
95 DumpError (lastQuery.lastError ());
UTIL_API ~DBLock()
Destructor.
DBLock(const DBLock &)=delete
static UTIL_API void DumpError(const QSqlError &error)
Dumps the error to the qWarning() stream.
UTIL_API void Good()
Notifies the lock about successful higher-level operations.
UTIL_API void Init()
Initializes the transaction.