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