Cutelyst  1.5.0
sql.h
1 /*
2  * Copyright (C) 2015-2016 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 Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 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  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this library; see the file COPYING.LIB. If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19 
20 #ifndef CSQL_H
21 #define CSQL_H
22 
23 #include <QtCore/QVariant>
24 #include <QtSql/QSqlDatabase>
25 
26 #include <Cutelyst/cutelyst_global.h>
27 #include <Cutelyst/paramsmultimap.h>
28 
29 namespace Cutelyst {
30 
31 namespace Sql
32 {
38  CUTELYST_PLUGIN_UTILS_SQL_EXPORT QVariantHash queryToHashObject(QSqlQuery &query);
39 
45  CUTELYST_PLUGIN_UTILS_SQL_EXPORT QVariantList queryToHashList(QSqlQuery &query);
46 
52  CUTELYST_PLUGIN_UTILS_SQL_EXPORT QVariantMap queryToMapObject(QSqlQuery &query);
53 
60  CUTELYST_PLUGIN_UTILS_SQL_EXPORT QVariantList queryToMapList(QSqlQuery &query);
61 
67  CUTELYST_PLUGIN_UTILS_SQL_EXPORT void bindParamsToQuery(QSqlQuery &query, const Cutelyst::ParamsMultiMap &params, bool htmlEscaped = true);
68 
84  CUTELYST_PLUGIN_UTILS_SQL_EXPORT QSqlQuery preparedQuery(const QString &query, QSqlDatabase db = QSqlDatabase(), bool forwardOnly = true);
85 
89  CUTELYST_PLUGIN_UTILS_SQL_EXPORT QString databaseNameThread(const QString &dbName = QString());
90 
107  CUTELYST_PLUGIN_UTILS_SQL_EXPORT QSqlQuery preparedQueryThread(const QString &query, const QString &dbName = QString(), bool forwardOnly = true);
108 }
109 
110 }
111 
112 # define CPreparedSqlQueryForDatabase(str, db) \
113  ([]() -> QSqlQuery { \
114  static thread_local QSqlQuery query_temp = \
115  Cutelyst::Sql::preparedQuery(str, db); \
116  return query_temp; \
117  }()) \
118 
119 
120 # define CPreparedSqlQuery(str) \
121  ([]() -> QSqlQuery { \
122  static QSqlQuery query_temp = \
123  Cutelyst::Sql::preparedQuery(str); \
124  return query_temp; \
125  }()) \
126 
127 
128 # define CPreparedSqlQueryThread(str) \
129  ([]() -> QSqlQuery { \
130  static thread_local QSqlQuery query_temp = \
131  Cutelyst::Sql::preparedQueryThread(str); \
132  return query_temp; \
133  }()) \
134 
135 
136 # define CPreparedSqlQueryThreadForDB(str, db) \
137  ([]() -> QSqlQuery { \
138  static thread_local QSqlQuery query_temp = \
139  Cutelyst::Sql::preparedQueryThread(str, db); \
140  return query_temp; \
141  }()) \
142 
143 
144 #endif // CSQL_H
QMap< QString, QString > ParamsMultiMap
The Cutelyst namespace holds all public Cutelyst API.
Definition: Mainpage.dox:7