summaryrefslogtreecommitdiffstats
path: root/src/svnqt/cache/sqlite3
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-03-15 17:32:48 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-03-15 17:32:48 +0000
commite2f541c98dfa4081fa3ab3d28f08ea2309281884 (patch)
treecb721a55bc88753ddeb9754dc98ef45e2850ce30 /src/svnqt/cache/sqlite3
downloadtdesvn-e2f541c98dfa4081fa3ab3d28f08ea2309281884.tar.gz
tdesvn-e2f541c98dfa4081fa3ab3d28f08ea2309281884.zip
Added KDE3 version of kdesvn
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/kdesvn@1103685 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src/svnqt/cache/sqlite3')
-rw-r--r--src/svnqt/cache/sqlite3/README32
-rw-r--r--src/svnqt/cache/sqlite3/qsql_sqlite3.cpp485
-rw-r--r--src/svnqt/cache/sqlite3/qsql_sqlite3.h90
-rw-r--r--src/svnqt/cache/sqlite3/qsqlcachedresult.cpp260
-rw-r--r--src/svnqt/cache/sqlite3/qsqlcachedresult.h81
5 files changed, 948 insertions, 0 deletions
diff --git a/src/svnqt/cache/sqlite3/README b/src/svnqt/cache/sqlite3/README
new file mode 100644
index 0000000..e2f7914
--- /dev/null
+++ b/src/svnqt/cache/sqlite3/README
@@ -0,0 +1,32 @@
+With this driver you can access the files created by sqlite3 through
+the standard Qt sql module. The driver name is QSQLITE3.
+
+Although there are many other solutions to access such DB files, I think
+that using this driver has some advantages:
+
+--> You use the standard Qt interface so you can reuse exinting code or
+ switch to or from other DB types quite easily.
+
+--> Soft transition to Qt 4: Qt 4 supports sqlite3, you can prepare your
+ application now.
+
+--> The source of this driver is smaller than any other, you can incorporate
+ it on your application with little overhead and without requiring external
+ libraries.
+
+
+Developer note:
+
+The driver is a merge between the QSQLITE driver in Qt 3 and in Qt 4 beta 1, with
+small tweaks, so I think is quite stable and usable.
+Please report success or failure, thanks
+
+To compile
+
+qmake
+make
+cp sqldrivers/libqsqlite3.so $QTDIR/plugins/sqldrivers (probably as root)
+
+use it as any other Qt sql driver.
+
+Have fun, Stefano !!! \ No newline at end of file
diff --git a/src/svnqt/cache/sqlite3/qsql_sqlite3.cpp b/src/svnqt/cache/sqlite3/qsql_sqlite3.cpp
new file mode 100644
index 0000000..93010c1
--- /dev/null
+++ b/src/svnqt/cache/sqlite3/qsql_sqlite3.cpp
@@ -0,0 +1,485 @@
+/****************************************************************************
+**
+** Implementation of SQLite driver classes.
+**
+** Copyright (C) 1992-2003 Trolltech AS. All rights reserved.
+**
+** This file is part of the sql module of the Qt GUI Toolkit.
+** EDITIONS: FREE, ENTERPRISE
+**
+** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+**
+****************************************************************************/
+
+#include "qsql_sqlite3.h"
+
+#include <qdatetime.h>
+#include <qvaluevector.h>
+#include <qregexp.h>
+#include <qfile.h>
+#include <sqlite3.h>
+
+#if (QT_VERSION-0 < 0x030200)
+# include <qvector.h>
+# if !defined Q_WS_WIN32
+# include <unistd.h>
+# endif
+#else
+# include <qptrvector.h>
+# if !defined Q_WS_WIN32
+# include <unistd.h>
+# endif
+#endif
+
+typedef struct sqlite3_stmt sqlite3_stmt;
+
+#define QSQLITE3_DRIVER_NAME "QSQLITE3"
+
+static QVariant::Type qSqliteType(int tp)
+{
+ switch (tp) {
+ case SQLITE_INTEGER:
+ return QVariant::Int;
+ case SQLITE_FLOAT:
+ return QVariant::Double;
+ case SQLITE_BLOB:
+ return QVariant::ByteArray;
+ case SQLITE_TEXT:
+ default:
+ return QVariant::String;
+ }
+}
+
+static QSqlError qMakeError(sqlite3 *access, const QString &descr, QSqlError::Type type,
+ int errorCode = -1)
+{
+ return QSqlError(descr,
+ QString::fromUtf8(sqlite3_errmsg(access)),
+ type, errorCode);
+}
+
+class QSQLite3DriverPrivate
+{
+public:
+ QSQLite3DriverPrivate();
+ sqlite3 *access;
+ bool utf8;
+};
+
+QSQLite3DriverPrivate::QSQLite3DriverPrivate() : access(0)
+{
+ utf8 = true;
+}
+
+class QSQLite3ResultPrivate
+{
+public:
+ QSQLite3ResultPrivate(QSQLite3Result *res);
+ void cleanup();
+ bool fetchNext(QSqlCachedResult::ValueCache &values, int idx, bool initialFetch);
+ bool isSelect();
+ // initializes the recordInfo and the cache
+ void initColumns();
+ void finalize();
+
+ QSQLite3Result* q;
+ sqlite3 *access;
+
+ sqlite3_stmt *stmt;
+
+ uint skippedStatus: 1; // the status of the fetchNext() that's skipped
+ uint skipRow: 1; // skip the next fetchNext()?
+ uint utf8: 1;
+ QSqlRecord rInf;
+};
+
+static const uint initial_cache_size = 128;
+
+QSQLite3ResultPrivate::QSQLite3ResultPrivate(QSQLite3Result* res) : q(res), access(0),
+ stmt(0), skippedStatus(false), skipRow(false), utf8(false)
+{
+}
+
+void QSQLite3ResultPrivate::cleanup()
+{
+ finalize();
+ rInf.clear();
+ skippedStatus = false;
+ skipRow = false;
+ q->setAt(QSql::BeforeFirst);
+ q->setActive(false);
+ q->cleanup();
+}
+
+void QSQLite3ResultPrivate::finalize()
+{
+ if (!stmt)
+ return;
+
+ sqlite3_finalize(stmt);
+ stmt = 0;
+}
+
+// called on first fetch
+void QSQLite3ResultPrivate::initColumns()
+{
+ rInf.clear();
+
+ int nCols = sqlite3_column_count(stmt);
+ if (nCols <= 0)
+ return;
+
+ q->init(nCols);
+
+ for (int i = 0; i < nCols; ++i) {
+ QString colName = QString::fromUtf8(sqlite3_column_name(stmt, i));
+
+ int dotIdx = colName.findRev('.');
+ rInf.append(QSqlField(colName.mid(dotIdx == -1 ? 0 : dotIdx + 1),
+ qSqliteType(sqlite3_column_type(stmt, i))));
+ }
+}
+
+bool QSQLite3ResultPrivate::fetchNext(QSqlCachedResult::ValueCache &values, int idx, bool initialFetch)
+{
+ int res;
+ unsigned int i;
+
+ if (skipRow) {
+ // already fetched
+ Q_ASSERT(!initialFetch);
+ skipRow = false;
+ return skippedStatus;
+ }
+ skipRow = initialFetch;
+
+ if (!stmt)
+ return false;
+
+ // keep trying while busy, wish I could implement this better.
+ while ((res = sqlite3_step(stmt)) == SQLITE_BUSY) {
+ // sleep instead requesting result again immidiately.
+#if defined Q_OS_WIN
+ Sleep(1000);
+#else
+ sleep(1);
+#endif
+ }
+
+ switch(res) {
+ case SQLITE_ROW:
+ // check to see if should fill out columns
+ if (rInf.isEmpty())
+ // must be first call.
+ initColumns();
+ if (idx < 0 && !initialFetch)
+ return true;
+ for (i = 0; i < rInf.count(); ++i)
+ // todo - handle other types
+ values[i + idx] = QString::fromUtf8((char *)(sqlite3_column_text(stmt, i)));
+ // values[i + idx] = utf8 ? QString::fromUtf8(fvals[i]) : QString::fromAscii(fvals[i]);
+ return true;
+ case SQLITE_DONE:
+ if (rInf.isEmpty())
+ // must be first call.
+ initColumns();
+ q->setAt(QSql::AfterLast);
+ return false;
+ case SQLITE_ERROR:
+ case SQLITE_MISUSE:
+ default:
+ // something wrong, don't get col info, but still return false
+ q->setLastError(qMakeError(access, "Unable to fetch row", QSqlError::Connection, res));
+ finalize();
+ q->setAt(QSql::AfterLast);
+ return false;
+ }
+ return false;
+}
+
+QSQLite3Result::QSQLite3Result(const QSQLite3Driver* db)
+ : QSqlCachedResult(db)
+{
+ d = new QSQLite3ResultPrivate(this);
+ d->access = db->d->access;
+}
+
+QSQLite3Result::~QSQLite3Result()
+{
+ d->cleanup();
+ delete d;
+}
+
+/*
+ Execute \a query.
+*/
+bool QSQLite3Result::reset (const QString &query)
+{
+ // this is where we build a query.
+ if (!driver() || !driver()->isOpen() || driver()->isOpenError())
+ return false;
+
+ d->cleanup();
+
+ setSelect(false);
+
+ int res = sqlite3_prepare(d->access, query.utf8().data(), (query.length() + 1) * sizeof(QChar),
+ &d->stmt, 0);
+
+ if (res != SQLITE_OK) {
+ setLastError(qMakeError(d->access, "Unable to execute statement", QSqlError::Statement, res));
+ d->finalize();
+ return false;
+ }
+
+ d->skippedStatus = d->fetchNext(cache(), 0, true);
+
+ setSelect(!d->rInf.isEmpty());
+ setActive(true);
+ return true;
+}
+
+bool QSQLite3Result::gotoNext(QSqlCachedResult::ValueCache& row, int idx)
+{
+ return d->fetchNext(row, idx, false);
+}
+
+int QSQLite3Result::size()
+{
+ return -1;
+}
+
+int QSQLite3Result::numRowsAffected()
+{
+ return sqlite3_changes(d->access);
+}
+
+/////////////////////////////////////////////////////////
+
+QSQLite3Driver::QSQLite3Driver(QObject * parent, const char *name)
+ : QSqlDriver(parent, name)
+{
+ d = new QSQLite3DriverPrivate();
+}
+
+QSQLite3Driver::QSQLite3Driver(sqlite3 *connection, QObject *parent, const char *name)
+ : QSqlDriver(parent, name)
+{
+ d = new QSQLite3DriverPrivate();
+ d->access = connection;
+ setOpen(true);
+ setOpenError(false);
+}
+
+
+QSQLite3Driver::~QSQLite3Driver()
+{
+ delete d;
+}
+
+bool QSQLite3Driver::hasFeature(DriverFeature f) const
+{
+ switch (f) {
+ case Transactions:
+ case Unicode:
+ case BLOB:
+ return true;
+ default:
+ break;
+ }
+ return false;
+}
+
+/*
+ SQLite dbs have no user name, passwords, hosts or ports.
+ just file names.
+*/
+bool QSQLite3Driver::open(const QString & db, const QString &, const QString &, const QString &, int, const QString &)
+{
+ if (isOpen())
+ close();
+
+ if (db.isEmpty())
+ return false;
+
+ if (sqlite3_open(QFile::encodeName(db), &d->access) == SQLITE_OK) {
+ setOpen(true);
+ setOpenError(false);
+ return true;
+ } else {
+ setLastError(qMakeError(d->access, "Error opening database",
+ QSqlError::Connection));
+ setOpenError(true);
+ return false;
+ }
+}
+
+void QSQLite3Driver::close()
+{
+ if (isOpen()) {
+ if (sqlite3_close(d->access) != SQLITE_OK)
+ setLastError(qMakeError(d->access, "Error closing database",
+ QSqlError::Connection));
+ d->access = 0;
+ setOpen(false);
+ setOpenError(false);
+ }
+}
+
+QSqlQuery QSQLite3Driver::createQuery() const
+{
+ return QSqlQuery(new QSQLite3Result(this));
+}
+
+bool QSQLite3Driver::beginTransaction()
+{
+ if (!isOpen() || isOpenError())
+ return false;
+
+ QSqlQuery q(createQuery());
+ if (!q.exec("BEGIN")) {
+ setLastError(QSqlError("Unable to begin transaction",
+ q.lastError().databaseText(), QSqlError::Transaction));
+ return false;
+ }
+
+ return true;
+}
+
+bool QSQLite3Driver::commitTransaction()
+{
+ if (!isOpen() || isOpenError())
+ return false;
+
+ QSqlQuery q(createQuery());
+ if (!q.exec("COMMIT")) {
+ setLastError(QSqlError("Unable to begin transaction",
+ q.lastError().databaseText(), QSqlError::Transaction));
+ return false;
+ }
+
+ return true;
+}
+
+bool QSQLite3Driver::rollbackTransaction()
+{
+ if (!isOpen() || isOpenError())
+ return false;
+
+ QSqlQuery q(createQuery());
+ if (!q.exec("ROLLBACK")) {
+ setLastError(QSqlError("Unable to begin transaction",
+ q.lastError().databaseText(), QSqlError::Transaction));
+ return false;
+ }
+
+ return true;
+}
+
+QStringList QSQLite3Driver::tables(const QString &typeName) const
+{
+ QStringList res;
+ if (!isOpen())
+ return res;
+ int type = typeName.toInt();
+
+ QSqlQuery q = createQuery();
+ q.setForwardOnly(TRUE);
+#if (QT_VERSION-0 >= 0x030200)
+ if ((type & (int)QSql::Tables) && (type & (int)QSql::Views))
+ q.exec("SELECT name FROM sqlite_master WHERE type='table' OR type='view'");
+ else if (typeName.isEmpty() || (type & (int)QSql::Tables))
+ q.exec("SELECT name FROM sqlite_master WHERE type='table'");
+ else if (type & (int)QSql::Views)
+ q.exec("SELECT name FROM sqlite_master WHERE type='view'");
+#else
+ q.exec("SELECT name FROM sqlite_master WHERE type='table' OR type='view'");
+#endif
+
+
+ if (q.isActive()) {
+ while(q.next())
+ res.append(q.value(0).toString());
+ }
+
+#if (QT_VERSION-0 >= 0x030200)
+ if (type & (int)QSql::SystemTables) {
+ // there are no internal tables beside this one:
+ res.append("sqlite_master");
+ }
+#endif
+
+ return res;
+}
+
+QSqlIndex QSQLite3Driver::primaryIndex(const QString &tblname) const
+{
+ QSqlRecordInfo rec(recordInfo(tblname)); // expensive :(
+
+ if (!isOpen())
+ return QSqlIndex();
+
+ QSqlQuery q = createQuery();
+ q.setForwardOnly(TRUE);
+ // finrst find a UNIQUE INDEX
+ q.exec("PRAGMA index_list('" + tblname + "');");
+ QString indexname;
+ while(q.next()) {
+ if (q.value(2).toInt()==1) {
+ indexname = q.value(1).toString();
+ break;
+ }
+ }
+ if (indexname.isEmpty())
+ return QSqlIndex();
+
+ q.exec("PRAGMA index_info('" + indexname + "');");
+
+ QSqlIndex index(indexname);
+ while(q.next()) {
+ QString name = q.value(2).toString();
+ QSqlVariant::Type type = QSqlVariant::Invalid;
+ if (rec.contains(name))
+ type = rec.find(name).type();
+ index.append(QSqlField(name, type));
+ }
+ return index;
+}
+
+QSqlRecordInfo QSQLite3Driver::recordInfo(const QString &tbl) const
+{
+ if (!isOpen())
+ return QSqlRecordInfo();
+
+ QSqlQuery q = createQuery();
+ q.setForwardOnly(TRUE);
+ q.exec("SELECT * FROM " + tbl + " LIMIT 1");
+ return recordInfo(q);
+}
+
+QSqlRecord QSQLite3Driver::record(const QString &tblname) const
+{
+ if (!isOpen())
+ return QSqlRecord();
+
+ return recordInfo(tblname).toRecord();
+}
+
+QSqlRecord QSQLite3Driver::record(const QSqlQuery& query) const
+{
+ if (query.isActive() && query.driver() == this) {
+ QSQLite3Result* result = (QSQLite3Result*)query.result();
+ return result->d->rInf;
+ }
+ return QSqlRecord();
+}
+
+QSqlRecordInfo QSQLite3Driver::recordInfo(const QSqlQuery& query) const
+{
+ if (query.isActive() && query.driver() == this) {
+ QSQLite3Result* result = (QSQLite3Result*)query.result();
+ return QSqlRecordInfo(result->d->rInf);
+ }
+ return QSqlRecordInfo();
+}
diff --git a/src/svnqt/cache/sqlite3/qsql_sqlite3.h b/src/svnqt/cache/sqlite3/qsql_sqlite3.h
new file mode 100644
index 0000000..f89c038
--- /dev/null
+++ b/src/svnqt/cache/sqlite3/qsql_sqlite3.h
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** Definition of SQLite driver classes.
+**
+** Copyright (C) 1992-2003 Trolltech AS. All rights reserved.
+**
+** This file is part of the sql module of the Qt GUI Toolkit.
+** EDITIONS: FREE, ENTERPRISE
+**
+** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+**
+****************************************************************************/
+
+#ifndef QSQL_SQLITE3_H
+#define QSQL_SQLITE3_H
+
+#include <qsqldriver.h>
+#include <qsqlresult.h>
+#include <qsqlrecord.h>
+#include <qsqlindex.h>
+#include "qsqlcachedresult.h"
+
+#if (QT_VERSION-0 >= 0x030200)
+typedef QVariant QSqlVariant;
+#endif
+
+#if defined (Q_OS_WIN32)
+# include <qt_windows.h>
+#endif
+
+class QSQLite3DriverPrivate;
+class QSQLite3ResultPrivate;
+class QSQLite3Driver;
+struct sqlite3;
+
+class QSQLite3Result : public QSqlCachedResult
+{
+ friend class QSQLite3Driver;
+ friend class QSQLite3ResultPrivate;
+public:
+ QSQLite3Result(const QSQLite3Driver* db);
+ ~QSQLite3Result();
+
+protected:
+ bool gotoNext(QSqlCachedResult::ValueCache& row, int idx);
+ bool reset (const QString& query);
+ int size();
+ int numRowsAffected();
+
+private:
+ QSQLite3ResultPrivate* d;
+};
+
+class QSQLite3Driver : public QSqlDriver
+{
+ friend class QSQLite3Result;
+public:
+ QSQLite3Driver(QObject *parent = 0, const char *name = 0);
+ QSQLite3Driver(sqlite3 *connection, QObject *parent = 0, const char *name = 0);
+ ~QSQLite3Driver();
+ bool hasFeature(DriverFeature f) const;
+ bool open(const QString & db,
+ const QString & user,
+ const QString & password,
+ const QString & host,
+ int port,
+ const QString & connOpts);
+ bool open( const QString & db,
+ const QString & user,
+ const QString & password,
+ const QString & host,
+ int port ) { return open (db, user, password, host, port, QString()); }
+ void close();
+ QSqlQuery createQuery() const;
+ bool beginTransaction();
+ bool commitTransaction();
+ bool rollbackTransaction();
+ QStringList tables(const QString &user) const;
+
+ QSqlRecord record(const QString& tablename) const;
+ QSqlRecordInfo recordInfo(const QString& tablename) const;
+ QSqlIndex primaryIndex(const QString &table) const;
+ QSqlRecord record(const QSqlQuery& query) const;
+ QSqlRecordInfo recordInfo(const QSqlQuery& query) const;
+
+private:
+ QSQLite3DriverPrivate* d;
+};
+#endif
diff --git a/src/svnqt/cache/sqlite3/qsqlcachedresult.cpp b/src/svnqt/cache/sqlite3/qsqlcachedresult.cpp
new file mode 100644
index 0000000..8a23183
--- /dev/null
+++ b/src/svnqt/cache/sqlite3/qsqlcachedresult.cpp
@@ -0,0 +1,260 @@
+/****************************************************************************
+**
+** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
+**
+** This file is part of the sql module of the Qt Toolkit.
+**
+** This file may be distributed under the terms of the Q Public License
+** as defined by Trolltech AS of Norway and appearing in the file
+** LICENSE.QPL included in the packaging of this file.
+**
+** This file may be distributed and/or modified under the terms of the
+** GNU General Public License version 2 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.
+**
+** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
+** information about Qt Commercial License Agreements.
+** See http://www.trolltech.com/qpl/ for QPL licensing information.
+** See http://www.trolltech.com/gpl/ for GPL licensing information.
+**
+** Contact info@trolltech.com if any conditions of this licensing are
+** not clear to you.
+**
+** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+**
+****************************************************************************/
+
+#include "qsqlcachedresult.h"
+
+#include <qvariant.h>
+#include <qdatetime.h>
+#include <qvaluevector.h>
+
+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;
+};
+
+QSqlCachedResultPrivate::QSqlCachedResultPrivate():
+ rowCacheEnd(0), colCount(0), forwardOnly(false)
+{
+}
+
+void QSqlCachedResultPrivate::cleanup()
+{
+ cache.clear();
+ forwardOnly = false;
+ colCount = 0;
+ rowCacheEnd = 0;
+}
+
+void QSqlCachedResultPrivate::init(int count, bool fo)
+{
+ Q_ASSERT(count);
+ cleanup();
+ forwardOnly = fo;
+ colCount = count;
+ if (fo) {
+ cache.resize(count);
+ rowCacheEnd = count;
+ } else {
+ cache.resize(initial_cache_size * count);
+ }
+}
+
+int QSqlCachedResultPrivate::nextIndex()
+{
+ if (forwardOnly)
+ return 0;
+ int newIdx = rowCacheEnd;
+ if (rowCacheEnd == (int)cache.size())
+ cache.resize(cache.size() * 2);
+/* if (newIdx + colCount > cache.size()){
+ if(cache.size() * 2 < cache.size() + 10000)
+ cache.resize(cache.size() * 2);
+ else
+ cache.resize(cache.size() + 10000);
+ }*/
+ rowCacheEnd += colCount;
+
+ return newIdx;
+}
+
+bool QSqlCachedResultPrivate::canSeek(int i) const
+{
+ if (forwardOnly || i < 0)
+ return false;
+ return rowCacheEnd >= (i + 1) * colCount;
+}
+
+void QSqlCachedResultPrivate::revertLast()
+{
+ if (forwardOnly)
+ return;
+ rowCacheEnd -= colCount;
+}
+
+inline int QSqlCachedResultPrivate::cacheCount() const
+{
+ Q_ASSERT(!forwardOnly);
+ Q_ASSERT(colCount);
+ return rowCacheEnd / colCount;
+}
+
+//////////////
+
+QSqlCachedResult::QSqlCachedResult(const QSqlDriver * db): QSqlResult (db)
+{
+ d = new QSqlCachedResultPrivate();
+}
+
+QSqlCachedResult::~QSqlCachedResult()
+{
+ delete d;
+}
+
+void QSqlCachedResult::init(int colCount)
+{
+ d->init(colCount, isForwardOnly());
+}
+
+bool QSqlCachedResult::fetch(int i)
+{
+ if ((!isActive()) || (i < 0))
+ return false;
+ if (at() == i)
+ return true;
+ if (d->forwardOnly) {
+ // speed hack - do not copy values if not needed
+ if (at() > i || at() == QSql::AfterLast)
+ return false;
+ while(at() < i - 1) {
+ if (!gotoNext(d->cache, -1))
+ return false;
+ setAt(at() + 1);
+ }
+ if (!gotoNext(d->cache, 0))
+ return false;
+ setAt(at() + 1);
+ return true;
+ }
+ if (d->canSeek(i)) {
+ setAt(i);
+ return true;
+ }
+ if (d->rowCacheEnd > 0)
+ setAt(d->cacheCount()-1);
+ while (at() < i) {
+ if (!cacheNext())
+ return false;
+ }
+ return true;
+}
+
+bool QSqlCachedResult::fetchNext()
+{
+ if (d->canSeek(at() + 1)) {
+ setAt(at() + 1);
+ return true;
+ }
+ return cacheNext();
+}
+
+bool QSqlCachedResult::fetchPrevious()
+{
+ return fetch(at() - 1);
+}
+
+bool QSqlCachedResult::fetchFirst()
+{
+ if (d->forwardOnly && at() != QSql::BeforeFirst) {
+ return false;
+ }
+ if (d->canSeek(0)) {
+ setAt(0);
+ return true;
+ }
+ return cacheNext();
+}
+
+bool QSqlCachedResult::fetchLast()
+{
+ if (at() == QSql::AfterLast) {
+ if (d->forwardOnly)
+ return false;
+ else
+ return fetch(d->cacheCount() - 1);
+ }
+
+ int i = at();
+ while (fetchNext())
+ ++i; /* brute force */
+ if (d->forwardOnly && at() == QSql::AfterLast) {
+ setAt(i);
+ return true;
+ } else {
+ return fetch(i);
+ }
+}
+
+QVariant QSqlCachedResult::data(int i)
+{
+ int idx = d->forwardOnly ? i : at() * d->colCount + i;
+ if (i >= d->colCount || i < 0 || at() < 0 || idx >= d->rowCacheEnd)
+ return QVariant();
+
+ return d->cache.at(idx);
+}
+
+bool QSqlCachedResult::isNull(int i)
+{
+ int idx = d->forwardOnly ? i : at() * d->colCount + i;
+ if (i > d->colCount || i < 0 || at() < 0 || idx >= d->rowCacheEnd)
+ return true;
+
+ return d->cache.at(idx).isNull();
+}
+
+void QSqlCachedResult::cleanup()
+{
+ setAt(QSql::BeforeFirst);
+ setActive(false);
+ d->cleanup();
+}
+
+bool QSqlCachedResult::cacheNext()
+{
+ if (!gotoNext(d->cache, d->nextIndex())) {
+ d->revertLast();
+ return false;
+ }
+ setAt(at() + 1);
+ return true;
+}
+
+int QSqlCachedResult::colCount() const
+{
+ return d->colCount;
+}
+
+QSqlCachedResult::ValueCache &QSqlCachedResult::cache()
+{
+ return d->cache;
+}
+
diff --git a/src/svnqt/cache/sqlite3/qsqlcachedresult.h b/src/svnqt/cache/sqlite3/qsqlcachedresult.h
new file mode 100644
index 0000000..fa8924f
--- /dev/null
+++ b/src/svnqt/cache/sqlite3/qsqlcachedresult.h
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
+**
+** This file is part of the sql module of the Qt Toolkit.
+**
+** This file may be distributed under the terms of the Q Public License
+** as defined by Trolltech AS of Norway and appearing in the file
+** LICENSE.QPL included in the packaging of this file.
+**
+** This file may be distributed and/or modified under the terms of the
+** GNU General Public License version 2 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.
+**
+** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
+** information about Qt Commercial License Agreements.
+** See http://www.trolltech.com/qpl/ for QPL licensing information.
+** See http://www.trolltech.com/gpl/ for GPL licensing information.
+**
+** Contact info@trolltech.com if any conditions of this licensing are
+** not clear to you.
+**
+** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+**
+****************************************************************************/
+
+#ifndef QSQLCACHEDRESULT_P_H
+#define QSQLCACHEDRESULT_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of other Qt classes. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <qsqlresult.h>
+
+class QVariant;
+template <typename T> class QValueVector;
+
+class QSqlCachedResultPrivate;
+
+class QM_EXPORT_SQL QSqlCachedResult: public QSqlResult
+{
+public:
+ virtual ~QSqlCachedResult();
+
+ typedef QValueVector<QVariant> ValueCache;
+
+protected:
+ QSqlCachedResult(const QSqlDriver * db);
+
+ void init(int colCount);
+ void cleanup();
+
+ virtual bool gotoNext(ValueCache &values, int index) = 0;
+
+ QVariant data(int i);
+ bool isNull(int i);
+ bool fetch(int i);
+ bool fetchNext();
+ bool fetchPrevious();
+ bool fetchFirst();
+ bool fetchLast();
+
+ int colCount() const;
+ ValueCache &cache();
+
+private:
+ bool cacheNext();
+ QSqlCachedResultPrivate *d;
+};
+
+#endif // QSQLCACHEDRESULT_P_H