FougTools  0.7.0dev-046fb6a
Handy tools for C++, Qt and OpenCascade
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
qsql_query_utils.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** FougTools
3 ** Copyright Fougue (30 Mar. 2015)
4 ** contact@fougue.pro
5 **
6 ** This software is a computer program whose purpose is to provide utility
7 ** tools for the C++ language and the Qt toolkit.
8 **
9 ** This software is governed by the CeCILL-C license under French law and
10 ** abiding by the rules of distribution of free software. You can use,
11 ** modify and/ or redistribute the software under the terms of the CeCILL-C
12 ** license as circulated by CEA, CNRS and INRIA at the following URL
13 ** "http://www.cecill.info".
14 ****************************************************************************/
15 
16 #pragma once
17 
18 #include "sql.h"
19 #include <stdexcept>
20 #include <QtSql/QSqlDatabase>
21 #include <QtSql/QSqlError>
22 #include <QtSql/QSqlQuery>
23 
24 namespace qtsql {
25 
26 class QTTOOLS_SQL_EXPORT SqlQueryError : public std::runtime_error
27 {
28 public:
29  SqlQueryError(const QSqlQuery& qry);
30  SqlQueryError(const QSqlError& err);
31  ~SqlQueryError() throw();
32 
33  QSqlError sqlError() const;
34 
35 private:
36  QSqlError m_sqlError;
37 };
38 
40 QSqlQuery execSqlCode(const QString& sqlCode, const QSqlDatabase& db);
42 QSqlQuery execSqlCodeInTransaction(const QString& sqlCode, QSqlDatabase db);
43 
45 void throwIfError(const QSqlQuery& qry);
46 
47 } // namespace qtsql
Provides a std::runtime_error that can convey a QSqlError object.
Definition: qsql_query_utils.h:26
void throwIfError(const QSqlQuery &qry)
Throw SqlQueryError if SQL query qry has error.
Definition: qsql_query_utils.cpp:93
#define QTTOOLS_SQL_EXPORT
Definition: sql.h:27
QSqlQuery execSqlCode(const QString &sqlCode, const QSqlDatabase &db)
Execute SQL statements in code use databse connection db.
Definition: qsql_query_utils.cpp:55
Definition: composite_type_helper.cpp:21
QSqlQuery execSqlCodeInTransaction(const QString &sqlCode, QSqlDatabase db)
Same as qtsql::execSqlCode() but execution performs inside a transaction.
Definition: qsql_query_utils.cpp:75