Cutelyst  2.5.0
sql.h
1 /*
2  * Copyright (C) 2015-2017 Daniel Nicoletti <dantti12@gmail.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 #ifndef CSQL_H
19 #define CSQL_H
20 
21 #include <QtCore/QVariant>
22 #include <QtSql/QSqlDatabase>
23 
24 #include <Cutelyst/cutelyst_global.h>
25 #include <Cutelyst/paramsmultimap.h>
26 
27 namespace Cutelyst {
28 
29 namespace Sql
30 {
36  CUTELYST_PLUGIN_UTILS_SQL_EXPORT QVariantHash queryToHashObject(QSqlQuery &query);
37 
43  CUTELYST_PLUGIN_UTILS_SQL_EXPORT QVariantList queryToHashList(QSqlQuery &query);
44 
50  CUTELYST_PLUGIN_UTILS_SQL_EXPORT QVariantMap queryToMapObject(QSqlQuery &query);
51 
56  CUTELYST_PLUGIN_UTILS_SQL_EXPORT QJsonObject queryToJsonObject(QSqlQuery &query);
57 
64  CUTELYST_PLUGIN_UTILS_SQL_EXPORT QVariantList queryToMapList(QSqlQuery &query);
65 
69  CUTELYST_PLUGIN_UTILS_SQL_EXPORT QJsonArray queryToJsonObjectArray(QSqlQuery &query);
70 
75  CUTELYST_PLUGIN_UTILS_SQL_EXPORT QVariantList queryToList(QSqlQuery &query);
76 
81  CUTELYST_PLUGIN_UTILS_SQL_EXPORT QJsonArray queryToJsonArray(QSqlQuery &query);
82 
88  CUTELYST_PLUGIN_UTILS_SQL_EXPORT QVariantHash queryToIndexedHash(QSqlQuery &query, const QString &key);
89 
95  CUTELYST_PLUGIN_UTILS_SQL_EXPORT QJsonObject queryToIndexedJsonObject(QSqlQuery &query, const QString &key);
96 
102  CUTELYST_PLUGIN_UTILS_SQL_EXPORT void bindParamsToQuery(QSqlQuery &query, const Cutelyst::ParamsMultiMap &params, bool htmlEscaped = true);
103 
119  CUTELYST_PLUGIN_UTILS_SQL_EXPORT QSqlQuery preparedQuery(const QString &query, QSqlDatabase db = QSqlDatabase(), bool forwardOnly = true);
120 
124  CUTELYST_PLUGIN_UTILS_SQL_EXPORT QString databaseNameThread(const QString &dbName = QString());
125 
129  CUTELYST_PLUGIN_UTILS_SQL_EXPORT QSqlDatabase databaseThread(const QString &dbName = QString());
130 
147  CUTELYST_PLUGIN_UTILS_SQL_EXPORT QSqlQuery preparedQueryThread(const QString &query, const QString &dbName = QString(), bool forwardOnly = true);
148 }
149 
150 }
151 
152 # define CPreparedSqlQueryForDatabase(str, db) \
153  ([]() -> QSqlQuery { \
154  static thread_local QSqlQuery query_temp = \
155  Cutelyst::Sql::preparedQuery(str, db); \
156  return query_temp; \
157  }()) \
158 
159 
160 # define CPreparedSqlQuery(str) \
161  ([]() -> QSqlQuery { \
162  static QSqlQuery query_temp = \
163  Cutelyst::Sql::preparedQuery(str); \
164  return query_temp; \
165  }()) \
166 
167 
168 # define CPreparedSqlQueryThread(str) \
169  ([]() -> QSqlQuery { \
170  static thread_local QSqlQuery query_temp = \
171  Cutelyst::Sql::preparedQueryThread(str); \
172  return query_temp; \
173  }()) \
174 
175 
176 # define CPreparedSqlQueryThreadForDB(str, db) \
177  ([]() -> QSqlQuery { \
178  static thread_local QSqlQuery query_temp = \
179  Cutelyst::Sql::preparedQueryThread(str, db); \
180  return query_temp; \
181  }()) \
182 
183 
184 #endif // CSQL_H
QMap< QString, QString > ParamsMultiMap
The Cutelyst namespace holds all public Cutelyst API.
Definition: Mainpage.dox:7