17 QSqlQuery
RunTextQuery (
const QSqlDatabase& db,
const QString& text)
19 QSqlQuery query { db };
20 if (!query.exec (text))
22 qDebug () <<
"unable to execute query";
24 throw std::runtime_error {
"unable to execute query" };
29 QString
LoadQuery (
const QString& pluginName,
const QString& filename)
31 QFile file {
":/" + pluginName +
"/resources/sql/" + filename +
".sql" };
32 if (!file.open (QIODevice::ReadOnly))
34 qWarning () << Q_FUNC_INFO
36 << file.errorString ();
37 throw std::runtime_error {
"Cannot open query file" };
40 return QString::fromUtf8 (file.readAll ());
43 void RunQuery (
const QSqlDatabase& db,
const QString& pluginName,
const QString& filename)
45 QSqlQuery query { db };
46 query.prepare (
LoadQuery (pluginName, filename));
52 return (base +
".%1_%2")
54 .arg (
reinterpret_cast<uintptr_t
> (QThread::currentThread ()));
static UTIL_DB_API void Execute(QSqlQuery &query)
Tries to execute the given query.
static UTIL_DB_API void DumpError(const QSqlError &error)
Dumps the error to the qWarning() stream.
QSqlQuery RunTextQuery(const QSqlDatabase &db, const QString &text)
Runs the given query text on the given db.
QString LoadQuery(const QString &pluginName, const QString &filename)
Loads the query text from the given resource file.
QString GenConnectionName(const QString &base)
Generates an unique thread-safe connection name.
void RunQuery(const QSqlDatabase &db, const QString &pluginName, const QString &filename)
Loads the query from the given resource file and runs it.