TreeFrogFramework  1.18
tsqldatabase.h
Go to the documentation of this file.
1 #ifndef TSQLDATABASE_H
2 #define TSQLDATABASE_H
3 
4 #include <QStringList>
5 #include <QSqlDatabase>
6 #include <QSqlDriver>
7 #include <TGlobal>
8 
10 
11 
13 {
14 public:
15 #if QT_VERSION >= 0x050400
16  enum DbmsType {
17  UnknownDbms = QSqlDriver::UnknownDbms,
18  MSSqlServer = QSqlDriver::MSSqlServer,
19  MySqlServer = QSqlDriver::MySqlServer,
20  PostgreSQL = QSqlDriver::PostgreSQL,
21  Oracle = QSqlDriver::Oracle,
22  Sybase = QSqlDriver::Sybase,
23  SQLite = QSqlDriver::SQLite,
24  Interbase = QSqlDriver::Interbase,
25  DB2 = QSqlDriver::DB2
26  };
27 #else
28  enum DbmsType {
37  DB2
38  };
39 #endif
40 
41  explicit TSqlDatabase(const QSqlDatabase &database = QSqlDatabase());
42  TSqlDatabase(const TSqlDatabase &other);
44  TSqlDatabase &operator=(const TSqlDatabase &other);
45 
46  DbmsType dbmsType() const;
47  bool isValid() const { return _sqlDatabase.isValid(); }
48  QString connectionName() const { return _sqlDatabase.connectionName(); }
49  const QSqlDatabase &sqlDatabase() const { return _sqlDatabase; }
50  QSqlDatabase &sqlDatabase() { return _sqlDatabase; }
51  QStringList postOpenStatements() const { return _postOpenStatements; }
52  void setPostOpenStatements(const QStringList &statements) { _postOpenStatements = statements; }
53  bool isUpsertEnabled() const { return _enableUpsert; }
54  void setUpsertEnabled(bool enable) { _enableUpsert = enable; }
55  bool isUpsertSupported() const;
56  const TSqlDriverExtension *driverExtension() const { return _driverExtension; }
57  void setDriverExtension(TSqlDriverExtension *extension);
58 
59  static const char *const defaultConnection;
60  static const TSqlDatabase &database(const QString &connectionName = QLatin1String(defaultConnection));
61  static TSqlDatabase &addDatabase(const QString &driver, const QString &connectionName = QLatin1String(defaultConnection));
62  static void removeDatabase(const QString &connectionName = QLatin1String(defaultConnection));
63  static bool contains(const QString &connectionName = QLatin1String(defaultConnection));
64 
65 private:
66  QSqlDatabase _sqlDatabase;
67  QStringList _postOpenStatements;
68  bool _enableUpsert {false};
69  TSqlDriverExtension *_driverExtension {nullptr};
70 };
71 
72 
73 inline TSqlDatabase::TSqlDatabase(const QSqlDatabase &database)
74  : _sqlDatabase(database)
75 {}
76 
78  : _sqlDatabase(other._sqlDatabase), _postOpenStatements(other._postOpenStatements),
79  _enableUpsert(other._enableUpsert), _driverExtension(other._driverExtension)
80 {}
81 
83 {
84  _sqlDatabase = other._sqlDatabase;
85  _postOpenStatements = other._postOpenStatements;
86  _enableUpsert = other._enableUpsert;
87  _driverExtension = other._driverExtension;
88  return *this;
89 }
90 
91 #endif // TSQLDATABASE_H
#define T_CORE_EXPORT
Definition: tglobal.h:81
DbmsType
Definition: tsqldatabase.h:28
static const char *const defaultConnection
Definition: tsqldatabase.h:59
~TSqlDatabase()
Definition: tsqldatabase.h:43
Definition: tsqldatabase.h:34
void setUpsertEnabled(bool enable)
Definition: tsqldatabase.h:54
TSqlDatabase(const QSqlDatabase &database=QSqlDatabase())
Definition: tsqldatabase.h:73
const TSqlDriverExtension * driverExtension() const
Definition: tsqldatabase.h:56
Definition: tsqldatabase.h:29
Definition: tsqldatabase.h:30
void setPostOpenStatements(const QStringList &statements)
Definition: tsqldatabase.h:52
QString connectionName() const
Definition: tsqldatabase.h:48
Definition: tsqldatabase.h:36
Definition: tsqldriverextension.h:10
Definition: tsqldatabase.h:35
Definition: tsqldatabase.h:31
Definition: tsqldatabase.h:33
bool isUpsertEnabled() const
Definition: tsqldatabase.h:53
const QSqlDatabase & sqlDatabase() const
Definition: tsqldatabase.h:49
QSqlDatabase & sqlDatabase()
Definition: tsqldatabase.h:50
bool isValid() const
Definition: tsqldatabase.h:47
QStringList postOpenStatements() const
Definition: tsqldatabase.h:51
TSqlDatabase & operator=(const TSqlDatabase &other)
Definition: tsqldatabase.h:82
Definition: tsqldatabase.h:32
Definition: tsqldatabase.h:12