LeechCraft 0.6.70-16373-g319c272718
Modular cross-platform feature rich live environment.
Loading...
Searching...
No Matches
util.cpp
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#include "util.h"
10#include <QFile>
11#include <QSqlQuery>
12#include <QThread>
13#include <QRandomGenerator>
14#include "dblock.h"
15
16namespace LC::Util
17{
19 {
20 QSqlQuery query { db };
21 if (!query.exec (text))
22 {
23 qDebug () << "unable to execute query";
25 throw std::runtime_error { "unable to execute query" };
26 }
27 return query;
28 }
29
31 {
32 QFile file { ":/" + pluginName + "/resources/sql/" + filename + ".sql" };
33 if (!file.open (QIODevice::ReadOnly))
34 {
36 << file.fileName ()
37 << file.errorString ();
38 throw std::runtime_error { "Cannot open query file" };
39 }
40
41 return QString::fromUtf8 (file.readAll ());
42 }
43
45 {
46 QSqlQuery query { db };
49 }
50
52 {
53 return (base + ".%1_%2")
54 .arg (QRandomGenerator::global ()->generate ())
55 .arg (std::bit_cast<uintptr_t> (QThread::currentThread ()));
56 }
57}
static UTIL_DB_API void Execute(QSqlQuery &query)
Tries to execute the given query.
Definition dblock.cpp:85
static UTIL_DB_API void DumpError(const QSqlError &error)
Dumps the error to the qWarning() stream.
Definition dblock.cpp:68
QSqlQuery RunTextQuery(const QSqlDatabase &db, const QString &text)
Runs the given query text on the given db.
Definition util.cpp:18
QString LoadQuery(const QString &pluginName, const QString &filename)
Loads the query text from the given resource file.
Definition util.cpp:30
QString GenConnectionName(const QString &base)
Generates an unique thread-safe connection name.
Definition util.cpp:51
void RunQuery(const QSqlDatabase &db, const QString &pluginName, const QString &filename)
Loads the query from the given resource file and runs it.
Definition util.cpp:44
Container< T > Filter(const Container< T > &c, F f)
Definition prelude.h:118