 |
LeechCraft
0.6.70-15082-g543737046d
Modular cross-platform feature rich live environment.
|
Go to the documentation of this file.
13 #include <QRandomGenerator>
18 QSqlQuery
RunTextQuery (
const QSqlDatabase& db,
const QString& text)
20 QSqlQuery query { db };
21 if (!query.exec (text))
23 qDebug () <<
"unable to execute query";
25 throw std::runtime_error {
"unable to execute query" };
30 QString
LoadQuery (
const QString& pluginName,
const QString& filename)
32 QFile file {
":/" + pluginName +
"/resources/sql/" + filename +
".sql" };
33 if (!file.open (QIODevice::ReadOnly))
35 qWarning () << Q_FUNC_INFO
37 << file.errorString ();
38 throw std::runtime_error {
"Cannot open query file" };
41 return QString::fromUtf8 (file.readAll ());
44 void RunQuery (
const QSqlDatabase& db,
const QString& pluginName,
const QString& filename)
46 QSqlQuery query { db };
47 query.prepare (
LoadQuery (pluginName, filename));
53 return (base +
".%1_%2")
54 .arg (QRandomGenerator::global ()->generate ())
55 .arg (std::bit_cast<uintptr_t> (QThread::currentThread ()));
static UTIL_DB_API void DumpError(const QSqlError &error)
Dumps the error to the qWarning() stream.
void RunQuery(const QSqlDatabase &db, const QString &pluginName, const QString &filename)
Loads the query from the given resource file and runs it.
QString LoadQuery(const QString &pluginName, const QString &filename)
Loads the query text from the given resource file.
QSqlQuery RunTextQuery(const QSqlDatabase &db, const QString &text)
Runs the given query text on the given db.
static UTIL_DB_API void Execute(QSqlQuery &query)
Tries to execute the given query.
QString GenConnectionName(const QString &base)
Generates an unique thread-safe connection name.