10 #include <QLoggingCategory>
12 #include <QtSql/QSqlError>
13 #include <QtSql/QSqlQuery>
14 #include <QtSql/QSqlRecord>
16 Q_LOGGING_CATEGORY(C_SQL,
"cutelyst.utils.sql", QtWarningMsg)
25 const int columns = record.
count();
26 for (
int i = 0; i < columns; ++i) {
37 const int columns = record.
count();
39 for (
int i = 0; i < columns; ++i) {
43 while (query.
next()) {
45 for (
int i = 0; i < columns; ++i) {
46 line.insert(cols.
at(i), query.
value(i));
58 const int columns = record.
count();
59 for (
int i = 0; i < columns; ++i) {
71 const int columns = record.
count();
72 for (
int i = 0; i < columns; ++i) {
83 const int columns = record.
count();
85 for (
int i = 0; i < columns; ++i) {
89 while (query.
next()) {
91 for (
int i = 0; i < columns; ++i) {
92 line.insert(cols.
at(i), query.
value(i));
103 const int columns = record.
count();
105 for (
int i = 0; i < columns; ++i) {
109 while (query.
next()) {
111 for (
int i = 0; i < columns; ++i) {
124 while (query.
next()) {
126 for (
int i = 0; i < columns; ++i) {
127 line.append(query.
value(i));
140 while (query.
next()) {
142 for (
int i = 0; i < columns; ++i) {
156 int index = record.
indexOf(key);
158 qCCritical(C_SQL) <<
"Field Name " << key <<
" not found in result set";
162 const int columns = record.
count();
165 for (
int i = 0; i < columns; ++i) {
169 while (query.
next()) {
171 for (
int i = 0; i < columns; ++i) {
173 line.insert(cols.
at(i), query.
value(i));
188 int index = record.
indexOf(key);
190 qCCritical(C_SQL) <<
"Field Name " << key <<
" not found in result set";
194 const int columns = record.
count();
197 for (
int i = 0; i < columns; ++i) {
201 while (query.
next()) {
203 for (
int i = 0; i < columns; ++i) {
222 if (it.value().isNull()) {
225 query.
bindValue(u
':' + it.key(), it.value().toHtmlEscaped());
231 if (it.value().isNull()) {
234 query.
bindValue(u
':' + it.key(), it.value());
245 if (!sqlQuery.
prepare(query)) {
246 qCCritical(C_SQL) <<
"Failed to prepare query:" << query
256 if (!sqlQuery.
prepare(query)) {
257 qCCritical(C_SQL) <<
"Failed to prepare query:" << query
287 if (m_transactionRunning) {
294 return m_transactionRunning;
300 m_transactionRunning = !m_db.commit();
301 return !m_transactionRunning;
306 m_transactionRunning =
false;
307 return m_db.rollback();
Transaction(const QString &databaseName=QString())
CUTELYST_PLUGIN_UTILS_SQL_EXPORT QVariantList queryToHashList(QSqlQuery &query)
CUTELYST_PLUGIN_UTILS_SQL_EXPORT QVariantMap queryToMapObject(QSqlQuery &query)
CUTELYST_PLUGIN_UTILS_SQL_EXPORT QVariantHash queryToHashObject(QSqlQuery &query)
CUTELYST_PLUGIN_UTILS_SQL_EXPORT void bindParamsToQuery(QSqlQuery &query, const Cutelyst::ParamsMultiMap ¶ms, bool htmlEscaped=true)
CUTELYST_PLUGIN_UTILS_SQL_EXPORT QJsonArray queryToJsonObjectArray(QSqlQuery &query)
CUTELYST_PLUGIN_UTILS_SQL_EXPORT QString databaseNameThread(const QString &dbName=QString())
CUTELYST_PLUGIN_UTILS_SQL_EXPORT QSqlQuery preparedQuery(const QString &query, QSqlDatabase db=QSqlDatabase(), bool forwardOnly=false)
CUTELYST_PLUGIN_UTILS_SQL_EXPORT QVariantList queryToList(QSqlQuery &query)
CUTELYST_PLUGIN_UTILS_SQL_EXPORT QJsonObject queryToIndexedJsonObject(QSqlQuery &query, const QString &key)
CUTELYST_PLUGIN_UTILS_SQL_EXPORT QVariantList queryToMapList(QSqlQuery &query)
CUTELYST_PLUGIN_UTILS_SQL_EXPORT QSqlDatabase databaseThread(const QString &dbName=QString())
CUTELYST_PLUGIN_UTILS_SQL_EXPORT QVariantHash queryToIndexedHash(QSqlQuery &query, const QString &key)
CUTELYST_PLUGIN_UTILS_SQL_EXPORT QJsonArray queryToJsonArray(QSqlQuery &query)
CUTELYST_PLUGIN_UTILS_SQL_EXPORT QSqlQuery preparedQueryThread(const QString &query, const QString &dbName=QString(), bool forwardOnly=false)
CUTELYST_PLUGIN_UTILS_SQL_EXPORT QJsonObject queryToJsonObject(QSqlQuery &query)
The Cutelyst namespace holds all public Cutelyst API.
void append(const QJsonValue &value)
QJsonObject::iterator insert(QLatin1StringView key, const QJsonValue &value)
QJsonValue fromVariant(const QVariant &variant)
void append(QList::parameter_type value)
QList::const_reference at(qsizetype i) const const
QMultiMap::const_iterator constBegin() const const
QMultiMap::const_iterator constEnd() const const
QSqlDatabase database(const QString &connectionName, bool open)
QString databaseText() const const
void bindValue(const QString &placeholder, const QVariant &val, QSql::ParamType paramType)
QSqlError lastError() const const
bool prepare(const QString &query)
QSqlRecord record() const const
void setForwardOnly(bool forward)
QVariant value(const QString &name) const const
QString fieldName(int index) const const
int indexOf(const QString &name) const const
QThread * currentThread()
QVariant fromValue(T &&value)
QString toString() const const