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 QSQLCACHEDRESULT_P_H
5#define QSQLCACHEDRESULT_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 other Qt classes. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtSql/private/qtsqlglobal_p.h>
19#include "QtSql/qsqlresult.h"
20#include "QtSql/private/qsqlresult_p.h"
21#include <QtCore/qcontainerfwd.h>
22
23QT_BEGIN_NAMESPACE
24
25class QVariant;
26
27class QSqlCachedResultPrivate;
28
29class Q_SQL_EXPORT QSqlCachedResult: public QSqlResult
30{
31 Q_DECLARE_PRIVATE(QSqlCachedResult)
32
33public:
34 typedef QList<QVariant> ValueCache;
35
36protected:
37 QSqlCachedResult(QSqlCachedResultPrivate &d);
38
39 void init(int colCount);
40 void cleanup();
41 void clearValues();
42
43 virtual bool gotoNext(ValueCache &values, int index) = 0;
44
45 QVariant data(int i) override;
46 bool isNull(int i) override;
47 bool fetch(int i) override;
48 bool fetchNext() override;
49 bool fetchPrevious() override;
50 bool fetchFirst() override;
51 bool fetchLast() override;
52
53 int colCount() const;
54 ValueCache &cache();
55
56 void virtual_hook(int id, void *data) override;
57 void detachFromResultSet() override;
58 void setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy policy) override;
59private:
60 bool cacheNext();
61};
62
63class Q_SQL_EXPORT QSqlCachedResultPrivate: public QSqlResultPrivate
64{
65 Q_DECLARE_PUBLIC(QSqlCachedResult)
66
67public:
68 using QSqlResultPrivate::QSqlResultPrivate;
69
70 bool canSeek(int i) const;
71 inline int cacheCount() const;
72 void init(int count, bool fo);
73 void cleanup();
74 int nextIndex();
75 void revertLast();
76
77 QSqlCachedResult::ValueCache cache;
78 int rowCacheEnd = 0;
79 int colCount = 0;
80 bool atEnd = false;
81};
82
83QT_END_NAMESPACE
84
85#endif // QSQLCACHEDRESULT_P_H
86

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