11 #include <QSqlDatabase> 14 #include <QMutexLocker> 20 QSet<QString> DBLock::LockedBases_;
22 QMutex DBLock::LockedMutex_;
25 : Database_ { database }
35 !Database_.commit () :
36 !Database_.rollback ())
40 QMutexLocker locker (&LockedMutex_);
41 LockedBases_.remove (Database_.connectionName ());
48 QMutexLocker locker (&LockedMutex_);
49 const auto& conn = Database_.connectionName ();
50 if (LockedBases_.contains (conn))
55 if (!Database_.transaction ())
58 throw std::runtime_error (
"Could not start transaction");
70 qCritical () << lastError.text () <<
"|" 72 << lastError.nativeErrorCode ();
77 qCritical () <<
"query:" << lastQuery.lastQuery ().simplified ();
80 const auto& boundValues = lastQuery.boundValues ();
81 qCritical () <<
"bound keys:" << boundValues.size () << boundValues.keys ();
82 qCritical () <<
"bound values:" << boundValues;
91 throw std::runtime_error (
"Query execution failed.");
UTIL_DB_API void Init()
Initializes the transaction.
static UTIL_DB_API void DumpError(const QSqlError &error)
Dumps the error to the qWarning() stream.
static UTIL_DB_API void Execute(QSqlQuery &query)
Tries to execute the given query.
UTIL_DB_API ~DBLock()
Destructor.
UTIL_DB_API void Good()
Notifies the lock about successful higher-level operations.
DBLock(const DBLock &)=delete