QxOrm 1.4.9
C++ Object Relational Mapping library
Loading...
Searching...
No Matches
QxSqlDatabase.h
Go to the documentation of this file.
1/****************************************************************************
2**
3** https://www.qxorm.com/
4** Copyright (C) 2013 Lionel Marty (contact@qxorm.com)
5**
6** This file is part of the QxOrm library
7**
8** This software is provided 'as-is', without any express or implied
9** warranty. In no event will the authors be held liable for any
10** damages arising from the use of this software
11**
12** Commercial Usage
13** Licensees holding valid commercial QxOrm licenses may use this file in
14** accordance with the commercial license agreement provided with the
15** Software or, alternatively, in accordance with the terms contained in
16** a written agreement between you and Lionel Marty
17**
18** GNU General Public License Usage
19** Alternatively, this file may be used under the terms of the GNU
20** General Public License version 3.0 as published by the Free Software
21** Foundation and appearing in the file 'license.gpl3.txt' included in the
22** packaging of this file. Please review the following information to
23** ensure the GNU General Public License version 3.0 requirements will be
24** met : http://www.gnu.org/copyleft/gpl.html
25**
26** If you are unsure which license is appropriate for your use, or
27** if you have questions regarding the use of this file, please contact :
28** contact@qxorm.com
29**
30****************************************************************************/
31
32#ifndef _QX_SQL_DATABASE_H_
33#define _QX_SQL_DATABASE_H_
34
35#ifdef _MSC_VER
36#pragma once
37#endif
38
46#include <QtCore/qhash.h>
47#include <QtCore/qmutex.h>
48#include <QtCore/qthread.h>
49#include <QtCore/quuid.h>
50
51#include <QtSql/qsqldatabase.h>
52#include <QtSql/qsqlquery.h>
53#include <QtSql/qsqlerror.h>
54
56
58
59namespace qx {
60namespace dao {
61namespace detail {
62
63class IxDao_Helper;
64
65} // namespace detail
66} // namespace dao
67} // namespace qx
68
69namespace qx {
70
75class QX_DLL_EXPORT QxSqlDatabase : public QxSingleton<QxSqlDatabase>
76{
77
78 friend class QxSingleton<QxSqlDatabase>;
80
81public:
82
83 enum ph_style { ph_style_question_mark, ph_style_2_point_name, ph_style_at_name };
84
85 typedef std::function<void (QSqlDatabase &)> type_fct_db_open;
86
87private:
88
89 struct QxSqlDatabaseImpl;
90 std::unique_ptr<QxSqlDatabaseImpl> m_pImpl;
91
93 virtual ~QxSqlDatabase();
94
95public:
96
97 QString getDriverName() const;
98 QString getConnectOptions() const;
99 QString getDatabaseName() const;
100 QString getUserName() const;
101 QString getPassword() const;
102 QString getHostName() const;
103 int getPort() const;
104 bool getTraceSqlQuery() const;
105 bool getTraceSqlRecord() const;
120 QStringList getSqlDelimiterForTableName() const;
121 QStringList getSqlDelimiterForColumnName() const;
127
128 void setDriverName(const QString & s, bool bJustForCurrentThread = false, QSqlDatabase * pJustForThisDatabase = NULL);
129 void setConnectOptions(const QString & s, bool bJustForCurrentThread = false, QSqlDatabase * pJustForThisDatabase = NULL);
130 void setDatabaseName(const QString & s, bool bJustForCurrentThread = false, QSqlDatabase * pJustForThisDatabase = NULL);
131 void setUserName(const QString & s, bool bJustForCurrentThread = false, QSqlDatabase * pJustForThisDatabase = NULL);
132 void setPassword(const QString & s, bool bJustForCurrentThread = false, QSqlDatabase * pJustForThisDatabase = NULL);
133 void setHostName(const QString & s, bool bJustForCurrentThread = false, QSqlDatabase * pJustForThisDatabase = NULL);
134 void setPort(int i, bool bJustForCurrentThread = false, QSqlDatabase * pJustForThisDatabase = NULL);
135 void setTraceSqlQuery(bool b, bool bJustForCurrentThread = false, QSqlDatabase * pJustForThisDatabase = NULL);
136 void setTraceSqlRecord(bool b, bool bJustForCurrentThread = false, QSqlDatabase * pJustForThisDatabase = NULL);
137 void setTraceSqlBoundValues(bool b, bool bJustForCurrentThread = false, QSqlDatabase * pJustForThisDatabase = NULL);
138 void setTraceSqlBoundValuesOnError(bool b, bool bJustForCurrentThread = false, QSqlDatabase * pJustForThisDatabase = NULL);
139 void setSqlPlaceHolderStyle(ph_style e, bool bJustForCurrentThread = false, QSqlDatabase * pJustForThisDatabase = NULL);
140 void setSessionThrowable(bool b, bool bJustForCurrentThread = false, QSqlDatabase * pJustForThisDatabase = NULL);
141 void setSessionAutoTransaction(bool b, bool bJustForCurrentThread = false, QSqlDatabase * pJustForThisDatabase = NULL);
142 void setValidatorThrowable(bool b, bool bJustForCurrentThread = false, QSqlDatabase * pJustForThisDatabase = NULL);
143 void setSqlGenerator(qx::dao::detail::IxSqlGenerator_ptr p, bool bJustForCurrentThread = false, QSqlDatabase * pJustForThisDatabase = NULL);
144 void setAutoReplaceSqlAliasIntoQuery(bool b, bool bJustForCurrentThread = false, QSqlDatabase * pJustForThisDatabase = NULL);
145 void setVerifyOffsetRelation(bool b, bool bJustForCurrentThread = false, QSqlDatabase * pJustForThisDatabase = NULL);
146 void setAddAutoIncrementIdToUpdateQuery(bool b, bool bJustForCurrentThread = false, QSqlDatabase * pJustForThisDatabase = NULL);
147 void setForceParentIdToAllChildren(bool b, bool bJustForCurrentThread = false, QSqlDatabase * pJustForThisDatabase = NULL);
148 void setFctDatabaseOpen(type_fct_db_open fct, bool bJustForCurrentThread = false, QSqlDatabase * pJustForThisDatabase = NULL);
149 void setAddSqlSquareBracketsForTableName(bool b, bool bJustForCurrentThread = false, QSqlDatabase * pJustForThisDatabase = NULL);
150 void setAddSqlSquareBracketsForColumnName(bool b, bool bJustForCurrentThread = false, QSqlDatabase * pJustForThisDatabase = NULL);
151 void setFormatSqlQueryBeforeLogging(bool b, bool bJustForCurrentThread = false, QSqlDatabase * pJustForThisDatabase = NULL);
152 void setSqlDelimiterForTableName(const QStringList & lst, bool bJustForCurrentThread = false, QSqlDatabase * pJustForThisDatabase = NULL);
153 void setSqlDelimiterForColumnName(const QStringList & lst, bool bJustForCurrentThread = false, QSqlDatabase * pJustForThisDatabase = NULL);
154 void setSqlDelimiterForTableNameAlias(const QStringList & lst, bool bJustForCurrentThread = false, QSqlDatabase * pJustForThisDatabase = NULL);
155 void setSqlDelimiterForColumnNameAlias(const QStringList & lst, bool bJustForCurrentThread = false, QSqlDatabase * pJustForThisDatabase = NULL);
156 void setTraceSqlOnlySlowQueriesDatabase(int i, bool bJustForCurrentThread = false, QSqlDatabase * pJustForThisDatabase = NULL);
157 void setTraceSqlOnlySlowQueriesTotal(int i, bool bJustForCurrentThread = false, QSqlDatabase * pJustForThisDatabase = NULL);
158 void setDisplayTimerDetails(bool b, bool bJustForCurrentThread = false, QSqlDatabase * pJustForThisDatabase = NULL);
159
160 static QSqlDatabase getDatabase();
161 static QSqlDatabase getDatabase(QSqlError & dbError);
162 static QSqlDatabase getDatabaseCloned();
163 static QSqlDatabase checkDatabaseByThread();
164 static void closeAllDatabases();
165 static void clearAllDatabases();
166 static bool isEmpty();
167
169
171 void clearAllSettingsForDatabase(QSqlDatabase * p);
172
173protected:
174
175 bool setCurrentDatabaseByThread(QSqlDatabase * p);
177
178};
179
180} // namespace qx
181
183
184#endif // _QX_SQL_DATABASE_H_
Common interface for all SQL generators to build SQL query specific for each database.
#define QX_DLL_EXPORT
Definition QxMacro.h:182
#define QX_DLL_EXPORT_QX_SINGLETON_HPP(x)
Definition QxMacro.h:190
Concrete class to define a thread-safe singleton of QxOrm library.
qx::QxSingleton<T> : concrete class to define a thread-safe singleton of type T
Definition QxSingleton.h:59
qx::QxSqlDatabase : define all parameters to connect to database and retrieve a valid connection by t...
static bool isEmpty()
QStringList getSqlDelimiterForColumnName() const
void setSqlDelimiterForColumnNameAlias(const QStringList &lst, bool bJustForCurrentThread=false, QSqlDatabase *pJustForThisDatabase=NULL)
bool getTraceSqlRecord() const
static QSqlDatabase getDatabaseCloned()
bool getSessionThrowable() const
void setTraceSqlOnlySlowQueriesDatabase(int i, bool bJustForCurrentThread=false, QSqlDatabase *pJustForThisDatabase=NULL)
bool getAddSqlSquareBracketsForColumnName() const
bool getForceParentIdToAllChildren() const
bool getTraceSqlBoundValuesOnError() const
void clearAllSettingsForDatabase(QSqlDatabase *p)
void setSqlDelimiterForColumnName(const QStringList &lst, bool bJustForCurrentThread=false, QSqlDatabase *pJustForThisDatabase=NULL)
void setHostName(const QString &s, bool bJustForCurrentThread=false, QSqlDatabase *pJustForThisDatabase=NULL)
bool getVerifyOffsetRelation() const
void setFctDatabaseOpen(type_fct_db_open fct, bool bJustForCurrentThread=false, QSqlDatabase *pJustForThisDatabase=NULL)
QString getDriverName() const
int getTraceSqlOnlySlowQueriesDatabase() const
QString getDatabaseName() const
bool getValidatorThrowable() const
void setTraceSqlRecord(bool b, bool bJustForCurrentThread=false, QSqlDatabase *pJustForThisDatabase=NULL)
void setAddSqlSquareBracketsForTableName(bool b, bool bJustForCurrentThread=false, QSqlDatabase *pJustForThisDatabase=NULL)
static QSqlDatabase getDatabase()
bool getDisplayTimerDetails() const
QStringList getSqlDelimiterForTableName() const
void setSqlDelimiterForTableNameAlias(const QStringList &lst, bool bJustForCurrentThread=false, QSqlDatabase *pJustForThisDatabase=NULL)
void setSqlDelimiterForTableName(const QStringList &lst, bool bJustForCurrentThread=false, QSqlDatabase *pJustForThisDatabase=NULL)
std::unique_ptr< QxSqlDatabaseImpl > m_pImpl
Private implementation idiom.
void setSessionThrowable(bool b, bool bJustForCurrentThread=false, QSqlDatabase *pJustForThisDatabase=NULL)
bool getTraceSqlBoundValues() const
bool setCurrentDatabaseByThread(QSqlDatabase *p)
std::function< void(QSqlDatabase &)> type_fct_db_open
void setFormatSqlQueryBeforeLogging(bool b, bool bJustForCurrentThread=false, QSqlDatabase *pJustForThisDatabase=NULL)
static void clearAllDatabases()
static void closeAllDatabases()
ph_style getSqlPlaceHolderStyle() const
QString getUserName() const
bool getFormatSqlQueryBeforeLogging() const
void setSqlPlaceHolderStyle(ph_style e, bool bJustForCurrentThread=false, QSqlDatabase *pJustForThisDatabase=NULL)
void setTraceSqlQuery(bool b, bool bJustForCurrentThread=false, QSqlDatabase *pJustForThisDatabase=NULL)
bool getAutoReplaceSqlAliasIntoQuery() const
void setSqlGenerator(qx::dao::detail::IxSqlGenerator_ptr p, bool bJustForCurrentThread=false, QSqlDatabase *pJustForThisDatabase=NULL)
bool getAddSqlSquareBracketsForTableName() const
virtual ~QxSqlDatabase()
void setUserName(const QString &s, bool bJustForCurrentThread=false, QSqlDatabase *pJustForThisDatabase=NULL)
QString getConnectOptions() const
int getTraceSqlOnlySlowQueriesTotal() const
void setTraceSqlBoundValues(bool b, bool bJustForCurrentThread=false, QSqlDatabase *pJustForThisDatabase=NULL)
void setPassword(const QString &s, bool bJustForCurrentThread=false, QSqlDatabase *pJustForThisDatabase=NULL)
QString getPassword() const
void clearAllSettingsForCurrentThread()
void setAddSqlSquareBracketsForColumnName(bool b, bool bJustForCurrentThread=false, QSqlDatabase *pJustForThisDatabase=NULL)
QStringList getSqlDelimiterForColumnNameAlias() const
void setVerifyOffsetRelation(bool b, bool bJustForCurrentThread=false, QSqlDatabase *pJustForThisDatabase=NULL)
void setForceParentIdToAllChildren(bool b, bool bJustForCurrentThread=false, QSqlDatabase *pJustForThisDatabase=NULL)
void setSessionAutoTransaction(bool b, bool bJustForCurrentThread=false, QSqlDatabase *pJustForThisDatabase=NULL)
type_fct_db_open getFctDatabaseOpen() const
int getPort() const
void setValidatorThrowable(bool b, bool bJustForCurrentThread=false, QSqlDatabase *pJustForThisDatabase=NULL)
QStringList getSqlDelimiterForTableNameAlias() const
void setAddAutoIncrementIdToUpdateQuery(bool b, bool bJustForCurrentThread=false, QSqlDatabase *pJustForThisDatabase=NULL)
void setTraceSqlBoundValuesOnError(bool b, bool bJustForCurrentThread=false, QSqlDatabase *pJustForThisDatabase=NULL)
static QSqlDatabase getDatabase(QSqlError &dbError)
bool getSessionAutoTransaction() const
void setDatabaseName(const QString &s, bool bJustForCurrentThread=false, QSqlDatabase *pJustForThisDatabase=NULL)
void setConnectOptions(const QString &s, bool bJustForCurrentThread=false, QSqlDatabase *pJustForThisDatabase=NULL)
void setPort(int i, bool bJustForCurrentThread=false, QSqlDatabase *pJustForThisDatabase=NULL)
QString getHostName() const
void setDisplayTimerDetails(bool b, bool bJustForCurrentThread=false, QSqlDatabase *pJustForThisDatabase=NULL)
static QSqlDatabase checkDatabaseByThread()
bool getAddAutoIncrementIdToUpdateQuery() const
qx::dao::detail::IxSqlGenerator * getSqlGenerator()
bool getTraceSqlQuery() const
void setDriverName(const QString &s, bool bJustForCurrentThread=false, QSqlDatabase *pJustForThisDatabase=NULL)
void setAutoReplaceSqlAliasIntoQuery(bool b, bool bJustForCurrentThread=false, QSqlDatabase *pJustForThisDatabase=NULL)
void clearCurrentDatabaseByThread()
void setTraceSqlOnlySlowQueriesTotal(int i, bool bJustForCurrentThread=false, QSqlDatabase *pJustForThisDatabase=NULL)
qx::dao::detail::IxDao_Helper : helper class to communicate with database
qx::dao::detail::IxSqlGenerator : common interface for all SQL generators to build SQL query specific...
std::shared_ptr< IxSqlGenerator > IxSqlGenerator_ptr
Root namespace for all QxOrm library features.