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