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 QSQLRESULT_H
41 #define QSQLRESULT_H
42 
43 #include <QtSql/qtsqlglobal.h>
44 #include <QtCore/qvariant.h>
45 #include <QtCore/qvector.h>
46 
47 // for testing:
48 class tst_QSqlQuery;
49 
50 QT_BEGIN_NAMESPACE
51 
52 
53 class QString;
54 class QSqlRecord;
55 template <typename T> class QVector;
56 class QVariant;
57 class QSqlDriver;
58 class QSqlError;
59 class QSqlResultPrivate;
60 
61 class Q_SQL_EXPORT QSqlResult
62 {
63     Q_DECLARE_PRIVATE(QSqlResult)
64     friend class QSqlQuery;
65     friend class QSqlTableModelPrivate;
66     // for testing:
67     friend class ::tst_QSqlQuery;
68 
69 public:
70     virtual ~QSqlResult();
71     virtual QVariant handle() const;
72 
73 protected:
74     enum BindingSyntax {
75         PositionalBinding,
76         NamedBinding
77     };
78 
79     explicit QSqlResult(const QSqlDriver * db);
80     QSqlResult(QSqlResultPrivate &dd);
81     int at() const;
82     QString lastQuery() const;
83     QSqlError lastError() const;
84     bool isValid() const;
85     bool isActive() const;
86     bool isSelect() const;
87     bool isForwardOnly() const;
88     const QSqlDriver* driver() const;
89     virtual void setAt(int at);
90     virtual void setActive(bool a);
91     virtual void setLastError(const QSqlError& e);
92     virtual void setQuery(const QString& query);
93     virtual void setSelect(bool s);
94     virtual void setForwardOnly(bool forward);
95 
96     // prepared query support
97     virtual bool exec();
98     virtual bool prepare(const QString& query);
99     virtual bool savePrepare(const QString& sqlquery);
100     virtual void bindValue(int pos, const QVariant& val, QSql::ParamType type);
101     virtual void bindValue(const QString& placeholder, const QVariant& val,
102                            QSql::ParamType type);
103     void addBindValue(const QVariant& val, QSql::ParamType type);
104     QVariant boundValue(const QString& placeholder) const;
105     QVariant boundValue(int pos) const;
106     QSql::ParamType bindValueType(const QString& placeholder) const;
107     QSql::ParamType bindValueType(int pos) const;
108     int boundValueCount() const;
109     QVector<QVariant>& boundValues() const;
110     QString executedQuery() const;
111     QString boundValueName(int pos) const;
112     void clear();
113     bool hasOutValues() const;
114 
115     BindingSyntax bindingSyntax() const;
116 
117     virtual QVariant data(int i) = 0;
118     virtual bool isNull(int i) = 0;
119     virtual bool reset(const QString& sqlquery) = 0;
120     virtual bool fetch(int i) = 0;
121     virtual bool fetchNext();
122     virtual bool fetchPrevious();
123     virtual bool fetchFirst() = 0;
124     virtual bool fetchLast() = 0;
125     virtual int size() = 0;
126     virtual int numRowsAffected() = 0;
127     virtual QSqlRecord record() const;
128     virtual QVariant lastInsertId() const;
129 
130     enum VirtualHookOperation { };
131     virtual void virtual_hook(int id, void *data);
132     virtual bool execBatch(bool arrayBind = false);
133     virtual void detachFromResultSet();
134     virtual void setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy policy);
135     QSql::NumericalPrecisionPolicy numericalPrecisionPolicy() const;
136     virtual bool nextResult();
137     void resetBindCount(); // HACK
138 
139     QSqlResultPrivate *d_ptr;
140 
141 private:
142     Q_DISABLE_COPY(QSqlResult)
143 };
144 
145 QT_END_NAMESPACE
146 
147 #endif // QSQLRESULT_H
148