FougTools  0.7.0dev-046fb6a
Handy tools for C++, Qt and OpenCascade
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
database_manager.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 <QtCore/QThread>
20 #include <QtSql/QSqlDatabase>
21 #include <QtSql/QSqlQuery>
22 class QIODevice;
23 
24 namespace qtsql {
25 
27 {
28 public:
29  DatabaseManager(const QSqlDatabase& refDb);
30  virtual ~DatabaseManager();
31 
32  bool isDatabaseOpen(const QThread* inThread = QThread::currentThread()) const;
33  bool hasDatabase(const QThread* inThread = QThread::currentThread()) const;
34 
35  const QSqlDatabase& referenceDatabase() const;
36  QSqlDatabase database(const QThread* inThread = QThread::currentThread()) const;
37  virtual QSqlDatabase createDatabase(const QThread* inThread = QThread::currentThread());
38 
39  virtual QSqlQuery execSqlCode(const QString& sqlCode,
40  const QThread* inThread = QThread::currentThread()) const;
41  virtual QSqlQuery execSqlCodeInTransaction(const QString& sqlCode,
42  const QThread* inThread = QThread::currentThread()) const;
43 
44  // SQL output
45  bool isSqlOutputEnabled() const;
46  void setSqlOutputEnabled(bool on);
47 
48  QIODevice* sqlOutputDevice() const;
49  void setSqlOutputDevice(QIODevice* device);
50 
51 protected:
52  virtual void logSql(const QString& sqlCode, const QThread* inThread) const;
53 
54 private:
55  class Private;
56  Private* const d;
57 };
58 
59 } // namespace qtsql
Provides threading and SQL logging control over QSqlDatabase.
Definition: database_manager.h:26
#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