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_H
5#define QSQLRESULT_H
6
7#include <QtSql/qtsqlglobal.h>
8#include <QtCore/qvariant.h>
9#include <QtCore/qcontainerfwd.h>
10
11// for testing:
12class tst_QSqlQuery;
13
14QT_BEGIN_NAMESPACE
15
16
17class QString;
18class QSqlRecord;
19class QVariant;
20class QSqlDriver;
21class QSqlError;
22class QSqlResultPrivate;
23
24class Q_SQL_EXPORT QSqlResult
25{
26 Q_DECLARE_PRIVATE(QSqlResult)
27 friend class QSqlQuery;
28 friend class QSqlTableModelPrivate;
29 // for testing:
30 friend class ::tst_QSqlQuery;
31
32public:
33 virtual ~QSqlResult();
34 virtual QVariant handle() const;
35
36protected:
37 enum BindingSyntax {
38 PositionalBinding,
39 NamedBinding
40 };
41
42 explicit QSqlResult(const QSqlDriver * db);
43 QSqlResult(QSqlResultPrivate &dd);
44 int at() const;
45 QString lastQuery() const;
46 QSqlError lastError() const;
47 bool isValid() const;
48 bool isActive() const;
49 bool isSelect() const;
50 bool isForwardOnly() const;
51 const QSqlDriver* driver() const;
52 virtual void setAt(int at);
53 virtual void setActive(bool a);
54 virtual void setLastError(const QSqlError& e);
55 virtual void setQuery(const QString& query);
56 virtual void setSelect(bool s);
57 virtual void setForwardOnly(bool forward);
58
59 // prepared query support
60 virtual bool exec();
61 virtual bool prepare(const QString& query);
62 virtual bool savePrepare(const QString& sqlquery);
63 virtual void bindValue(int pos, const QVariant& val, QSql::ParamType type);
64 virtual void bindValue(const QString& placeholder, const QVariant& val,
65 QSql::ParamType type);
66 void addBindValue(const QVariant& val, QSql::ParamType type);
67 QVariant boundValue(const QString& placeholder) const;
68 QVariant boundValue(int pos) const;
69 QSql::ParamType bindValueType(const QString& placeholder) const;
70 QSql::ParamType bindValueType(int pos) const;
71 int boundValueCount() const;
72#if QT_SQL_REMOVED_SINCE(6, 6)
73 QList<QVariant> &boundValues() const;
74#endif
75 QVariantList &boundValues(QT6_DECL_NEW_OVERLOAD);
76 QVariantList boundValues(QT6_DECL_NEW_OVERLOAD) const;
77
78 QString executedQuery() const;
79 QStringList boundValueNames() const;
80 QString boundValueName(int pos) const;
81 void clear();
82 bool hasOutValues() const;
83
84 BindingSyntax bindingSyntax() const;
85
86 virtual QVariant data(int i) = 0;
87 virtual bool isNull(int i) = 0;
88 virtual bool reset(const QString& sqlquery) = 0;
89 virtual bool fetch(int i) = 0;
90 virtual bool fetchNext();
91 virtual bool fetchPrevious();
92 virtual bool fetchFirst() = 0;
93 virtual bool fetchLast() = 0;
94 virtual int size() = 0;
95 virtual int numRowsAffected() = 0;
96 virtual QSqlRecord record() const;
97 virtual QVariant lastInsertId() const;
98
99 enum VirtualHookOperation { };
100 virtual void virtual_hook(int id, void *data);
101 virtual bool execBatch(bool arrayBind = false);
102 virtual void detachFromResultSet();
103 virtual void setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy policy);
104 QSql::NumericalPrecisionPolicy numericalPrecisionPolicy() const;
105 virtual bool nextResult();
106 void resetBindCount(); // HACK
107
108 QSqlResultPrivate *d_ptr;
109
110private:
111 Q_DISABLE_COPY(QSqlResult)
112};
113
114QT_END_NAMESPACE
115
116#endif // QSQLRESULT_H
117

source code of qtbase/src/sql/kernel/qsqlresult.h