1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QSQLDRIVER_H |
5 | #define QSQLDRIVER_H |
6 | |
7 | #include <QtSql/qtsqlglobal.h> |
8 | #include <QtCore/qobject.h> |
9 | #include <QtCore/qstring.h> |
10 | #include <QtCore/qstringlist.h> |
11 | |
12 | QT_BEGIN_NAMESPACE |
13 | |
14 | |
15 | class QSqlDatabase; |
16 | class QSqlDriverPrivate; |
17 | class QSqlError; |
18 | class QSqlField; |
19 | class QSqlIndex; |
20 | class QSqlRecord; |
21 | class QSqlResult; |
22 | class QVariant; |
23 | |
24 | class Q_SQL_EXPORT QSqlDriver : public QObject |
25 | { |
26 | friend class QSqlDatabase; |
27 | friend class QSqlResultPrivate; |
28 | Q_OBJECT |
29 | Q_DECLARE_PRIVATE(QSqlDriver) |
30 | |
31 | public: |
32 | enum DriverFeature { Transactions, QuerySize, BLOB, Unicode, PreparedQueries, |
33 | NamedPlaceholders, PositionalPlaceholders, LastInsertId, |
34 | BatchOperations, SimpleLocking, LowPrecisionNumbers, |
35 | EventNotifications, FinishQuery, MultipleResultSets, CancelQuery }; |
36 | |
37 | enum StatementType { WhereStatement, SelectStatement, UpdateStatement, |
38 | InsertStatement, DeleteStatement }; |
39 | |
40 | enum IdentifierType { FieldName, TableName }; |
41 | |
42 | enum NotificationSource { UnknownSource, SelfSource, OtherSource }; |
43 | |
44 | enum DbmsType { |
45 | UnknownDbms, |
46 | MSSqlServer, |
47 | MySqlServer, |
48 | PostgreSQL, |
49 | Oracle, |
50 | Sybase, |
51 | SQLite, |
52 | Interbase, |
53 | DB2, |
54 | MimerSQL, |
55 | }; |
56 | |
57 | explicit QSqlDriver(QObject *parent = nullptr); |
58 | ~QSqlDriver(); |
59 | virtual bool isOpen() const; |
60 | bool isOpenError() const; |
61 | |
62 | virtual bool beginTransaction(); |
63 | virtual bool commitTransaction(); |
64 | virtual bool rollbackTransaction(); |
65 | virtual QStringList tables(QSql::TableType tableType) const; |
66 | virtual QSqlIndex primaryIndex(const QString &tableName) const; |
67 | virtual QSqlRecord record(const QString &tableName) const; |
68 | virtual QString formatValue(const QSqlField &field, bool trimStrings = false) const; |
69 | |
70 | virtual QString escapeIdentifier(const QString &identifier, IdentifierType type) const; |
71 | virtual QString sqlStatement(StatementType type, const QString &tableName, |
72 | const QSqlRecord &rec, bool preparedStatement) const; |
73 | |
74 | QSqlError lastError() const; |
75 | |
76 | virtual QVariant handle() const; |
77 | virtual bool hasFeature(DriverFeature f) const = 0; |
78 | virtual void close() = 0; |
79 | virtual QSqlResult *createResult() const = 0; |
80 | |
81 | virtual bool open(const QString &db, |
82 | const QString &user = QString(), |
83 | const QString &password = QString(), |
84 | const QString &host = QString(), |
85 | int port = -1, |
86 | const QString &connOpts = QString()) = 0; |
87 | virtual bool subscribeToNotification(const QString &name); |
88 | virtual bool unsubscribeFromNotification(const QString &name); |
89 | virtual QStringList subscribedToNotifications() const; |
90 | |
91 | virtual bool isIdentifierEscaped(const QString &identifier, IdentifierType type) const; |
92 | virtual QString stripDelimiters(const QString &identifier, IdentifierType type) const; |
93 | |
94 | void setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy precisionPolicy); |
95 | QSql::NumericalPrecisionPolicy numericalPrecisionPolicy() const; |
96 | |
97 | DbmsType dbmsType() const; |
98 | virtual int maximumIdentifierLength(IdentifierType type) const; |
99 | public Q_SLOTS: |
100 | virtual bool cancelQuery(); |
101 | |
102 | Q_SIGNALS: |
103 | void notification(const QString &name, QSqlDriver::NotificationSource source, const QVariant &payload); |
104 | |
105 | protected: |
106 | QSqlDriver(QSqlDriverPrivate &dd, QObject *parent = nullptr); |
107 | virtual void setOpen(bool o); |
108 | virtual void setOpenError(bool e); |
109 | virtual void setLastError(const QSqlError& e); |
110 | |
111 | |
112 | private: |
113 | Q_DISABLE_COPY(QSqlDriver) |
114 | }; |
115 | |
116 | QT_END_NAMESPACE |
117 | |
118 | #endif // QSQLDRIVER_H |
119 | |