Cutelyst  1.11.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 
58  CUTELYST_PLUGIN_UTILS_SQL_EXPORT QVariantList queryToMapList(QSqlQuery &query);
59 
65  CUTELYST_PLUGIN_UTILS_SQL_EXPORT QVariantHash queryToIndexedHash(QSqlQuery &query, const QString &key);
66 
72  CUTELYST_PLUGIN_UTILS_SQL_EXPORT void bindParamsToQuery(QSqlQuery &query, const Cutelyst::ParamsMultiMap &params, bool htmlEscaped = true);
73 
89  CUTELYST_PLUGIN_UTILS_SQL_EXPORT QSqlQuery preparedQuery(const QString &query, QSqlDatabase db = QSqlDatabase(), bool forwardOnly = true);
90 
94  CUTELYST_PLUGIN_UTILS_SQL_EXPORT QString databaseNameThread(const QString &dbName = QString());
95 
112  CUTELYST_PLUGIN_UTILS_SQL_EXPORT QSqlQuery preparedQueryThread(const QString &query, const QString &dbName = QString(), bool forwardOnly = true);
113 }
114 
115 }
116 
117 # define CPreparedSqlQueryForDatabase(str, db) \
118  ([]() -> QSqlQuery { \
119  static thread_local QSqlQuery query_temp = \
120  Cutelyst::Sql::preparedQuery(str, db); \
121  return query_temp; \
122  }()) \
123 
124 
125 # define CPreparedSqlQuery(str) \
126  ([]() -> QSqlQuery { \
127  static QSqlQuery query_temp = \
128  Cutelyst::Sql::preparedQuery(str); \
129  return query_temp; \
130  }()) \
131 
132 
133 # define CPreparedSqlQueryThread(str) \
134  ([]() -> QSqlQuery { \
135  static thread_local QSqlQuery query_temp = \
136  Cutelyst::Sql::preparedQueryThread(str); \
137  return query_temp; \
138  }()) \
139 
140 
141 # define CPreparedSqlQueryThreadForDB(str, db) \
142  ([]() -> QSqlQuery { \
143  static thread_local QSqlQuery query_temp = \
144  Cutelyst::Sql::preparedQueryThread(str, db); \
145  return query_temp; \
146  }()) \
147 
148 
149 #endif // CSQL_H
QMap< QString, QString > ParamsMultiMap
The Cutelyst namespace holds all public Cutelyst API.
Definition: Mainpage.dox:7