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 QSQLRESULT_P_H |
5 | #define QSQLRESULT_P_H |
6 | |
7 | // |
8 | // W A R N I N G |
9 | // ------------- |
10 | // |
11 | // This file is not part of the Qt API. It exists for the convenience |
12 | // of qsql*model.h . This header file may change from version to version |
13 | // without notice, or even be removed. |
14 | // |
15 | // We mean it. |
16 | // |
17 | |
18 | #include <QtSql/private/qtsqlglobal_p.h> |
19 | #include <QtCore/qpointer.h> |
20 | #include <QtCore/qhash.h> |
21 | #include "qsqlerror.h" |
22 | #include "qsqlresult.h" |
23 | #include "qsqldriver.h" |
24 | |
25 | QT_BEGIN_NAMESPACE |
26 | |
27 | // convenience method Q*ResultPrivate::drv_d_func() returns pointer to private driver. Compare to Q_DECLARE_PRIVATE in qglobal.h. |
28 | #define Q_DECLARE_SQLDRIVER_PRIVATE(Class) \ |
29 | inline const Class##Private* drv_d_func() const { return !sqldriver ? nullptr : reinterpret_cast<const Class *>(static_cast<const QSqlDriver*>(sqldriver))->d_func(); } \ |
30 | inline Class##Private* drv_d_func() { return !sqldriver ? nullptr : reinterpret_cast<Class *>(static_cast<QSqlDriver*>(sqldriver))->d_func(); } |
31 | |
32 | struct QHolder { |
33 | QHolder(const QString &hldr = QString(), qsizetype index = -1): holderName(hldr), holderPos(index) { } |
34 | bool operator==(const QHolder &h) const { return h.holderPos == holderPos && h.holderName == holderName; } |
35 | bool operator!=(const QHolder &h) const { return h.holderPos != holderPos || h.holderName != holderName; } |
36 | QString holderName; |
37 | qsizetype holderPos; |
38 | }; |
39 | |
40 | class Q_SQL_EXPORT QSqlResultPrivate |
41 | { |
42 | Q_DECLARE_PUBLIC(QSqlResult) |
43 | |
44 | public: |
45 | QSqlResultPrivate(QSqlResult *q, const QSqlDriver *drv) |
46 | : q_ptr(q), |
47 | sqldriver(const_cast<QSqlDriver *>(drv)) |
48 | { } |
49 | virtual ~QSqlResultPrivate() = default; |
50 | |
51 | void clearValues() |
52 | { |
53 | values.clear(); |
54 | bindCount = 0; |
55 | } |
56 | |
57 | void resetBindCount() |
58 | { |
59 | bindCount = 0; |
60 | } |
61 | |
62 | void clearIndex() |
63 | { |
64 | indexes.clear(); |
65 | holders.clear(); |
66 | types.clear(); |
67 | } |
68 | |
69 | void clear() |
70 | { |
71 | clearValues(); |
72 | clearIndex(); |
73 | } |
74 | |
75 | virtual QString fieldSerial(qsizetype) const; |
76 | QString positionalToNamedBinding(const QString &query) const; |
77 | QString namedToPositionalBinding(const QString &query); |
78 | QString holderAt(int index) const; |
79 | |
80 | QSqlResult *q_ptr = nullptr; |
81 | QPointer<QSqlDriver> sqldriver; |
82 | QString sql; |
83 | QSqlError error; |
84 | |
85 | QString executedQuery; |
86 | QHash<int, QSql::ParamType> types; |
87 | QList<QVariant> values; |
88 | using IndexMap = QHash<QString, QList<int>>; |
89 | IndexMap indexes; |
90 | |
91 | using QHolderVector = QList<QHolder>; |
92 | QHolderVector holders; |
93 | |
94 | QSqlResult::BindingSyntax binds = QSqlResult::PositionalBinding; |
95 | QSql::NumericalPrecisionPolicy precisionPolicy = QSql::LowPrecisionDouble; |
96 | int idx = QSql::BeforeFirstRow; |
97 | int bindCount = 0; |
98 | bool active = false; |
99 | bool isSel = false; |
100 | bool forwardOnly = false; |
101 | |
102 | static bool isVariantNull(const QVariant &variant); |
103 | }; |
104 | |
105 | QT_END_NAMESPACE |
106 | |
107 | #endif // QSQLRESULT_P_H |
108 |