1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the QtSql module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | |
40 | #ifndef QSQLDRIVER_H |
41 | #define QSQLDRIVER_H |
42 | |
43 | #include <QtSql/qtsqlglobal.h> |
44 | #include <QtCore/qobject.h> |
45 | #include <QtCore/qstring.h> |
46 | #include <QtCore/qstringlist.h> |
47 | |
48 | QT_BEGIN_NAMESPACE |
49 | |
50 | |
51 | class QSqlDatabase; |
52 | class QSqlDriverPrivate; |
53 | class QSqlError; |
54 | class QSqlField; |
55 | class QSqlIndex; |
56 | class QSqlRecord; |
57 | class QSqlResult; |
58 | class QVariant; |
59 | |
60 | class Q_SQL_EXPORT QSqlDriver : public QObject |
61 | { |
62 | friend class QSqlDatabase; |
63 | friend class QSqlResultPrivate; |
64 | Q_OBJECT |
65 | Q_DECLARE_PRIVATE(QSqlDriver) |
66 | |
67 | public: |
68 | enum DriverFeature { Transactions, QuerySize, BLOB, Unicode, PreparedQueries, |
69 | NamedPlaceholders, PositionalPlaceholders, LastInsertId, |
70 | BatchOperations, SimpleLocking, LowPrecisionNumbers, |
71 | EventNotifications, FinishQuery, MultipleResultSets, CancelQuery }; |
72 | |
73 | enum StatementType { WhereStatement, SelectStatement, UpdateStatement, |
74 | InsertStatement, DeleteStatement }; |
75 | |
76 | enum IdentifierType { FieldName, TableName }; |
77 | |
78 | enum NotificationSource { UnknownSource, SelfSource, OtherSource }; |
79 | |
80 | enum DbmsType { |
81 | UnknownDbms, |
82 | MSSqlServer, |
83 | MySqlServer, |
84 | PostgreSQL, |
85 | Oracle, |
86 | Sybase, |
87 | SQLite, |
88 | Interbase, |
89 | DB2 |
90 | }; |
91 | |
92 | explicit QSqlDriver(QObject *parent = nullptr); |
93 | ~QSqlDriver(); |
94 | virtual bool isOpen() const; |
95 | bool isOpenError() const; |
96 | |
97 | virtual bool beginTransaction(); |
98 | virtual bool commitTransaction(); |
99 | virtual bool rollbackTransaction(); |
100 | virtual QStringList tables(QSql::TableType tableType) const; |
101 | virtual QSqlIndex primaryIndex(const QString &tableName) const; |
102 | virtual QSqlRecord record(const QString &tableName) const; |
103 | virtual QString formatValue(const QSqlField &field, bool trimStrings = false) const; |
104 | |
105 | virtual QString escapeIdentifier(const QString &identifier, IdentifierType type) const; |
106 | virtual QString sqlStatement(StatementType type, const QString &tableName, |
107 | const QSqlRecord &rec, bool preparedStatement) const; |
108 | |
109 | QSqlError lastError() const; |
110 | |
111 | virtual QVariant handle() const; |
112 | virtual bool hasFeature(DriverFeature f) const = 0; |
113 | virtual void close() = 0; |
114 | virtual QSqlResult *createResult() const = 0; |
115 | |
116 | virtual bool open(const QString &db, |
117 | const QString &user = QString(), |
118 | const QString &password = QString(), |
119 | const QString &host = QString(), |
120 | int port = -1, |
121 | const QString &connOpts = QString()) = 0; |
122 | virtual bool subscribeToNotification(const QString &name); |
123 | virtual bool unsubscribeFromNotification(const QString &name); |
124 | virtual QStringList subscribedToNotifications() const; |
125 | |
126 | virtual bool isIdentifierEscaped(const QString &identifier, IdentifierType type) const; |
127 | virtual QString stripDelimiters(const QString &identifier, IdentifierType type) const; |
128 | |
129 | void setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy precisionPolicy); |
130 | QSql::NumericalPrecisionPolicy numericalPrecisionPolicy() const; |
131 | |
132 | DbmsType dbmsType() const; |
133 | virtual int maximumIdentifierLength(IdentifierType type) const; |
134 | public Q_SLOTS: |
135 | virtual bool cancelQuery(); |
136 | |
137 | Q_SIGNALS: |
138 | void notification(const QString &name, QSqlDriver::NotificationSource source, const QVariant &payload); |
139 | |
140 | protected: |
141 | QSqlDriver(QSqlDriverPrivate &dd, QObject *parent = nullptr); |
142 | virtual void setOpen(bool o); |
143 | virtual void setOpenError(bool e); |
144 | virtual void setLastError(const QSqlError& e); |
145 | |
146 | |
147 | private: |
148 | Q_DISABLE_COPY(QSqlDriver) |
149 | }; |
150 | |
151 | QT_END_NAMESPACE |
152 | |
153 | #endif // QSQLDRIVER_H |
154 | |