summaryrefslogtreecommitdiffstats
path: root/src/sql/kernel/qsqlcachedresult.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/sql/kernel/qsqlcachedresult.cpp')
-rw-r--r--src/sql/kernel/qsqlcachedresult.cpp83
1 files changed, 40 insertions, 43 deletions
diff --git a/src/sql/kernel/qsqlcachedresult.cpp b/src/sql/kernel/qsqlcachedresult.cpp
index b9611ae8c7..c335d7d8fe 100644
--- a/src/sql/kernel/qsqlcachedresult.cpp
+++ b/src/sql/kernel/qsqlcachedresult.cpp
@@ -1,31 +1,37 @@
/****************************************************************************
**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtSql module of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL21$
+** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
-** As a special exception, The Qt Company gives you certain additional
-** rights. These rights are described in The Qt Company LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
@@ -36,6 +42,7 @@
#include <qvariant.h>
#include <qdatetime.h>
#include <qvector.h>
+#include <QtSql/private/qsqldriver_p.h>
QT_BEGIN_NAMESPACE
@@ -53,33 +60,17 @@ QT_BEGIN_NAMESPACE
static const uint initial_cache_size = 128;
-class QSqlCachedResultPrivate
-{
-public:
- QSqlCachedResultPrivate();
- bool canSeek(int i) const;
- inline int cacheCount() const;
- void init(int count, bool fo);
- void cleanup();
- int nextIndex();
- void revertLast();
-
- QSqlCachedResult::ValueCache cache;
- int rowCacheEnd;
- int colCount;
- bool forwardOnly;
- bool atEnd;
-};
-
-QSqlCachedResultPrivate::QSqlCachedResultPrivate():
- rowCacheEnd(0), colCount(0), forwardOnly(false), atEnd(false)
+QSqlCachedResultPrivate::QSqlCachedResultPrivate(QSqlCachedResult *q, const QSqlDriver *drv)
+ : QSqlResultPrivate(q, drv),
+ rowCacheEnd(0),
+ colCount(0),
+ atEnd(false)
{
}
void QSqlCachedResultPrivate::cleanup()
{
cache.clear();
- forwardOnly = false;
atEnd = false;
colCount = 0;
rowCacheEnd = 0;
@@ -134,23 +125,20 @@ inline int QSqlCachedResultPrivate::cacheCount() const
//////////////
-QSqlCachedResult::QSqlCachedResult(const QSqlDriver * db): QSqlResult (db)
-{
- d = new QSqlCachedResultPrivate();
-}
-
-QSqlCachedResult::~QSqlCachedResult()
+QSqlCachedResult::QSqlCachedResult(QSqlCachedResultPrivate &d)
+ : QSqlResult(d)
{
- delete d;
}
void QSqlCachedResult::init(int colCount)
{
+ Q_D(QSqlCachedResult);
d->init(colCount, isForwardOnly());
}
bool QSqlCachedResult::fetch(int i)
{
+ Q_D(QSqlCachedResult);
if ((!isActive()) || (i < 0))
return false;
if (at() == i)
@@ -189,6 +177,7 @@ bool QSqlCachedResult::fetch(int i)
bool QSqlCachedResult::fetchNext()
{
+ Q_D(QSqlCachedResult);
if (d->canSeek(at() + 1)) {
setAt(at() + 1);
return true;
@@ -203,6 +192,7 @@ bool QSqlCachedResult::fetchPrevious()
bool QSqlCachedResult::fetchFirst()
{
+ Q_D(QSqlCachedResult);
if (d->forwardOnly && at() != QSql::BeforeFirstRow) {
return false;
}
@@ -215,6 +205,7 @@ bool QSqlCachedResult::fetchFirst()
bool QSqlCachedResult::fetchLast()
{
+ Q_D(QSqlCachedResult);
if (d->atEnd) {
if (d->forwardOnly)
return false;
@@ -235,6 +226,7 @@ bool QSqlCachedResult::fetchLast()
QVariant QSqlCachedResult::data(int i)
{
+ Q_D(const QSqlCachedResult);
int idx = d->forwardOnly ? i : at() * d->colCount + i;
if (i >= d->colCount || i < 0 || at() < 0 || idx >= d->rowCacheEnd)
return QVariant();
@@ -244,6 +236,7 @@ QVariant QSqlCachedResult::data(int i)
bool QSqlCachedResult::isNull(int i)
{
+ Q_D(const QSqlCachedResult);
int idx = d->forwardOnly ? i : at() * d->colCount + i;
if (i >= d->colCount || i < 0 || at() < 0 || idx >= d->rowCacheEnd)
return true;
@@ -253,6 +246,7 @@ bool QSqlCachedResult::isNull(int i)
void QSqlCachedResult::cleanup()
{
+ Q_D(QSqlCachedResult);
setAt(QSql::BeforeFirstRow);
setActive(false);
d->cleanup();
@@ -260,6 +254,7 @@ void QSqlCachedResult::cleanup()
void QSqlCachedResult::clearValues()
{
+ Q_D(QSqlCachedResult);
setAt(QSql::BeforeFirstRow);
d->rowCacheEnd = 0;
d->atEnd = false;
@@ -267,11 +262,11 @@ void QSqlCachedResult::clearValues()
bool QSqlCachedResult::cacheNext()
{
+ Q_D(QSqlCachedResult);
if (d->atEnd)
return false;
if(isForwardOnly()) {
- d->cache.clear();
d->cache.resize(d->colCount);
}
@@ -286,11 +281,13 @@ bool QSqlCachedResult::cacheNext()
int QSqlCachedResult::colCount() const
{
+ Q_D(const QSqlCachedResult);
return d->colCount;
}
QSqlCachedResult::ValueCache &QSqlCachedResult::cache()
{
+ Q_D(QSqlCachedResult);
return d->cache;
}