summaryrefslogtreecommitdiffstats
path: root/src/svnqt/cache/sqlite3/qsql_sqlite3.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/svnqt/cache/sqlite3/qsql_sqlite3.cpp')
-rw-r--r--src/svnqt/cache/sqlite3/qsql_sqlite3.cpp243
1 files changed, 115 insertions, 128 deletions
diff --git a/src/svnqt/cache/sqlite3/qsql_sqlite3.cpp b/src/svnqt/cache/sqlite3/qsql_sqlite3.cpp
index 93010c1..a5faff5 100644
--- a/src/svnqt/cache/sqlite3/qsql_sqlite3.cpp
+++ b/src/svnqt/cache/sqlite3/qsql_sqlite3.cpp
@@ -1,10 +1,10 @@
/****************************************************************************
**
-** Implementation of SQLite driver classes.
+** Implementation of STQLite driver classes.
**
** Copyright (C) 1992-2003 Trolltech AS. All rights reserved.
**
-** This file is part of the sql module of the Qt GUI Toolkit.
+** This file is part of the sql module of the TQt GUI Toolkit.
** EDITIONS: FREE, ENTERPRISE
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
@@ -14,105 +14,98 @@
#include "qsql_sqlite3.h"
-#include <qdatetime.h>
-#include <qvaluevector.h>
-#include <qregexp.h>
-#include <qfile.h>
+#include <tqdatetime.h>
+#include <tqvaluevector.h>
+#include <tqregexp.h>
+#include <tqfile.h>
#include <sqlite3.h>
-#if (QT_VERSION-0 < 0x030200)
-# include <qvector.h>
-# if !defined Q_WS_WIN32
+# include <tqptrvector.h>
+# if !defined TQ_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"
+#define TQSQLITE3_DRIVER_NAME "TQSQLITE3"
-static QVariant::Type qSqliteType(int tp)
+static TQVariant::Type qSqliteType(int tp)
{
switch (tp) {
case SQLITE_INTEGER:
- return QVariant::Int;
+ return TQVariant::Int;
case SQLITE_FLOAT:
- return QVariant::Double;
+ return TQVariant::Double;
case SQLITE_BLOB:
- return QVariant::ByteArray;
+ return TQVariant::ByteArray;
case SQLITE_TEXT:
default:
- return QVariant::String;
+ return TQVariant::String;
}
}
-static QSqlError qMakeError(sqlite3 *access, const QString &descr, QSqlError::Type type,
+static TQSqlError qMakeError(sqlite3 *access, const TQString &descr, TQSqlError::Type type,
int errorCode = -1)
{
- return QSqlError(descr,
- QString::fromUtf8(sqlite3_errmsg(access)),
+ return TQSqlError(descr,
+ TQString::fromUtf8(sqlite3_errmsg(access)),
type, errorCode);
}
-class QSQLite3DriverPrivate
+class TQSQLite3DriverPrivate
{
public:
- QSQLite3DriverPrivate();
+ TQSQLite3DriverPrivate();
sqlite3 *access;
bool utf8;
};
-QSQLite3DriverPrivate::QSQLite3DriverPrivate() : access(0)
+TQSQLite3DriverPrivate::TQSQLite3DriverPrivate() : access(0)
{
utf8 = true;
}
-class QSQLite3ResultPrivate
+class TQSQLite3ResultPrivate
{
public:
- QSQLite3ResultPrivate(QSQLite3Result *res);
+ TQSQLite3ResultPrivate(TQSQLite3Result *res);
void cleanup();
- bool fetchNext(QSqlCachedResult::ValueCache &values, int idx, bool initialFetch);
+ bool fetchNext(TQSqlCachedResult::ValueCache &values, int idx, bool initialFetch);
bool isSelect();
// initializes the recordInfo and the cache
void initColumns();
void finalize();
- QSQLite3Result* q;
+ TQSQLite3Result* q;
sqlite3 *access;
sqlite3_stmt *stmt;
- uint skippedStatus: 1; // the status of the fetchNext() that's skipped
+ uint skippedtqStatus: 1; // the status of the fetchNext() that's skipped
uint skipRow: 1; // skip the next fetchNext()?
uint utf8: 1;
- QSqlRecord rInf;
+ TQSqlRecord rInf;
};
static const uint initial_cache_size = 128;
-QSQLite3ResultPrivate::QSQLite3ResultPrivate(QSQLite3Result* res) : q(res), access(0),
- stmt(0), skippedStatus(false), skipRow(false), utf8(false)
+TQSQLite3ResultPrivate::TQSQLite3ResultPrivate(TQSQLite3Result* res) : q(res), access(0),
+ stmt(0), skippedtqStatus(false), skipRow(false), utf8(false)
{
}
-void QSQLite3ResultPrivate::cleanup()
+void TQSQLite3ResultPrivate::cleanup()
{
finalize();
rInf.clear();
- skippedStatus = false;
+ skippedtqStatus = false;
skipRow = false;
- q->setAt(QSql::BeforeFirst);
+ q->setAt(TQSql::BeforeFirst);
q->setActive(false);
q->cleanup();
}
-void QSQLite3ResultPrivate::finalize()
+void TQSQLite3ResultPrivate::finalize()
{
if (!stmt)
return;
@@ -122,7 +115,7 @@ void QSQLite3ResultPrivate::finalize()
}
// called on first fetch
-void QSQLite3ResultPrivate::initColumns()
+void TQSQLite3ResultPrivate::initColumns()
{
rInf.clear();
@@ -133,15 +126,15 @@ void QSQLite3ResultPrivate::initColumns()
q->init(nCols);
for (int i = 0; i < nCols; ++i) {
- QString colName = QString::fromUtf8(sqlite3_column_name(stmt, i));
+ TQString colName = TQString::fromUtf8(sqlite3_column_name(stmt, i));
- int dotIdx = colName.findRev('.');
- rInf.append(QSqlField(colName.mid(dotIdx == -1 ? 0 : dotIdx + 1),
+ int dotIdx = colName.tqfindRev('.');
+ rInf.append(TQSqlField(colName.mid(dotIdx == -1 ? 0 : dotIdx + 1),
qSqliteType(sqlite3_column_type(stmt, i))));
}
}
-bool QSQLite3ResultPrivate::fetchNext(QSqlCachedResult::ValueCache &values, int idx, bool initialFetch)
+bool TQSQLite3ResultPrivate::fetchNext(TQSqlCachedResult::ValueCache &values, int idx, bool initialFetch)
{
int res;
unsigned int i;
@@ -150,7 +143,7 @@ bool QSQLite3ResultPrivate::fetchNext(QSqlCachedResult::ValueCache &values, int
// already fetched
Q_ASSERT(!initialFetch);
skipRow = false;
- return skippedStatus;
+ return skippedtqStatus;
}
skipRow = initialFetch;
@@ -160,7 +153,7 @@ bool QSQLite3ResultPrivate::fetchNext(QSqlCachedResult::ValueCache &values, int
// 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
+#if defined TQ_OS_WIN
Sleep(1000);
#else
sleep(1);
@@ -177,35 +170,35 @@ bool QSQLite3ResultPrivate::fetchNext(QSqlCachedResult::ValueCache &values, int
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]);
+ values[i + idx] = TQString::fromUtf8((char *)(sqlite3_column_text(stmt, i)));
+ // values[i + idx] = utf8 ? TQString::fromUtf8(fvals[i]) : TQString::fromAscii(fvals[i]);
return true;
case SQLITE_DONE:
if (rInf.isEmpty())
// must be first call.
initColumns();
- q->setAt(QSql::AfterLast);
+ q->setAt(TQSql::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));
+ q->setLastError(qMakeError(access, "Unable to fetch row", TQSqlError::Connection, res));
finalize();
- q->setAt(QSql::AfterLast);
+ q->setAt(TQSql::AfterLast);
return false;
}
return false;
}
-QSQLite3Result::QSQLite3Result(const QSQLite3Driver* db)
- : QSqlCachedResult(db)
+TQSQLite3Result::TQSQLite3Result(const TQSQLite3Driver* db)
+ : TQSqlCachedResult(db)
{
- d = new QSQLite3ResultPrivate(this);
+ d = new TQSQLite3ResultPrivate(this);
d->access = db->d->access;
}
-QSQLite3Result::~QSQLite3Result()
+TQSQLite3Result::~TQSQLite3Result()
{
d->cleanup();
delete d;
@@ -214,7 +207,7 @@ QSQLite3Result::~QSQLite3Result()
/*
Execute \a query.
*/
-bool QSQLite3Result::reset (const QString &query)
+bool TQSQLite3Result::reset (const TQString &query)
{
// this is where we build a query.
if (!driver() || !driver()->isOpen() || driver()->isOpenError())
@@ -224,61 +217,61 @@ bool QSQLite3Result::reset (const QString &query)
setSelect(false);
- int res = sqlite3_prepare(d->access, query.utf8().data(), (query.length() + 1) * sizeof(QChar),
+ int res = sqlite3_prepare(d->access, query.utf8().data(), (query.length() + 1) * sizeof(TQChar),
&d->stmt, 0);
if (res != SQLITE_OK) {
- setLastError(qMakeError(d->access, "Unable to execute statement", QSqlError::Statement, res));
+ setLastError(qMakeError(d->access, "Unable to execute statement", TQSqlError::Statement, res));
d->finalize();
return false;
}
- d->skippedStatus = d->fetchNext(cache(), 0, true);
+ d->skippedtqStatus = d->fetchNext(cache(), 0, true);
setSelect(!d->rInf.isEmpty());
setActive(true);
return true;
}
-bool QSQLite3Result::gotoNext(QSqlCachedResult::ValueCache& row, int idx)
+bool TQSQLite3Result::gotoNext(TQSqlCachedResult::ValueCache& row, int idx)
{
return d->fetchNext(row, idx, false);
}
-int QSQLite3Result::size()
+int TQSQLite3Result::size()
{
return -1;
}
-int QSQLite3Result::numRowsAffected()
+int TQSQLite3Result::numRowsAffected()
{
return sqlite3_changes(d->access);
}
/////////////////////////////////////////////////////////
-QSQLite3Driver::QSQLite3Driver(QObject * parent, const char *name)
- : QSqlDriver(parent, name)
+TQSQLite3Driver::TQSQLite3Driver(TQObject * tqparent, const char *name)
+ : TQSqlDriver(tqparent, name)
{
- d = new QSQLite3DriverPrivate();
+ d = new TQSQLite3DriverPrivate();
}
-QSQLite3Driver::QSQLite3Driver(sqlite3 *connection, QObject *parent, const char *name)
- : QSqlDriver(parent, name)
+TQSQLite3Driver::TQSQLite3Driver(sqlite3 *connection, TQObject *tqparent, const char *name)
+ : TQSqlDriver(tqparent, name)
{
- d = new QSQLite3DriverPrivate();
+ d = new TQSQLite3DriverPrivate();
d->access = connection;
setOpen(true);
setOpenError(false);
}
-QSQLite3Driver::~QSQLite3Driver()
+TQSQLite3Driver::~TQSQLite3Driver()
{
delete d;
}
-bool QSQLite3Driver::hasFeature(DriverFeature f) const
+bool TQSQLite3Driver::hasFeature(DriverFeature f) const
{
switch (f) {
case Transactions:
@@ -292,10 +285,10 @@ bool QSQLite3Driver::hasFeature(DriverFeature f) const
}
/*
- SQLite dbs have no user name, passwords, hosts or ports.
+ STQLite 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 &)
+bool TQSQLite3Driver::open(const TQString & db, const TQString &, const TQString &, const TQString &, int, const TQString &)
{
if (isOpen())
close();
@@ -303,99 +296,95 @@ bool QSQLite3Driver::open(const QString & db, const QString &, const QString &,
if (db.isEmpty())
return false;
- if (sqlite3_open(QFile::encodeName(db), &d->access) == SQLITE_OK) {
+ if (sqlite3_open(TQFile::encodeName(db), &d->access) == SQLITE_OK) {
setOpen(true);
setOpenError(false);
return true;
} else {
setLastError(qMakeError(d->access, "Error opening database",
- QSqlError::Connection));
+ TQSqlError::Connection));
setOpenError(true);
return false;
}
}
-void QSQLite3Driver::close()
+void TQSQLite3Driver::close()
{
if (isOpen()) {
if (sqlite3_close(d->access) != SQLITE_OK)
setLastError(qMakeError(d->access, "Error closing database",
- QSqlError::Connection));
+ TQSqlError::Connection));
d->access = 0;
setOpen(false);
setOpenError(false);
}
}
-QSqlQuery QSQLite3Driver::createQuery() const
+TQSqlQuery TQSQLite3Driver::createQuery() const
{
- return QSqlQuery(new QSQLite3Result(this));
+ return TQSqlQuery(new TQSQLite3Result(this));
}
-bool QSQLite3Driver::beginTransaction()
+bool TQSQLite3Driver::beginTransaction()
{
if (!isOpen() || isOpenError())
return false;
- QSqlQuery q(createQuery());
+ TQSqlQuery q(createQuery());
if (!q.exec("BEGIN")) {
- setLastError(QSqlError("Unable to begin transaction",
- q.lastError().databaseText(), QSqlError::Transaction));
+ setLastError(TQSqlError("Unable to begin transaction",
+ q.lastError().databaseText(), TQSqlError::Transaction));
return false;
}
return true;
}
-bool QSQLite3Driver::commitTransaction()
+bool TQSQLite3Driver::commitTransaction()
{
if (!isOpen() || isOpenError())
return false;
- QSqlQuery q(createQuery());
+ TQSqlQuery q(createQuery());
if (!q.exec("COMMIT")) {
- setLastError(QSqlError("Unable to begin transaction",
- q.lastError().databaseText(), QSqlError::Transaction));
+ setLastError(TQSqlError("Unable to begin transaction",
+ q.lastError().databaseText(), TQSqlError::Transaction));
return false;
}
return true;
}
-bool QSQLite3Driver::rollbackTransaction()
+bool TQSQLite3Driver::rollbackTransaction()
{
if (!isOpen() || isOpenError())
return false;
- QSqlQuery q(createQuery());
+ TQSqlQuery q(createQuery());
if (!q.exec("ROLLBACK")) {
- setLastError(QSqlError("Unable to begin transaction",
- q.lastError().databaseText(), QSqlError::Transaction));
+ setLastError(TQSqlError("Unable to begin transaction",
+ q.lastError().databaseText(), TQSqlError::Transaction));
return false;
}
return true;
}
-QStringList QSQLite3Driver::tables(const QString &typeName) const
+TQStringList TQSQLite3Driver::tables(const TQString &typeName) const
{
- QStringList res;
+ TQStringList res;
if (!isOpen())
return res;
int type = typeName.toInt();
- QSqlQuery q = createQuery();
+ TQSqlQuery q = createQuery();
q.setForwardOnly(TRUE);
-#if (QT_VERSION-0 >= 0x030200)
- if ((type & (int)QSql::Tables) && (type & (int)QSql::Views))
+ if ((type & (int)TQSql::Tables) && (type & (int)TQSql::Views))
q.exec("SELECT name FROM sqlite_master WHERE type='table' OR type='view'");
- else if (typeName.isEmpty() || (type & (int)QSql::Tables))
+ else if (typeName.isEmpty() || (type & (int)TQSql::Tables))
q.exec("SELECT name FROM sqlite_master WHERE type='table'");
- else if (type & (int)QSql::Views)
+ else if (type & (int)TQSql::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()) {
@@ -403,28 +392,26 @@ QStringList QSQLite3Driver::tables(const QString &typeName) const
res.append(q.value(0).toString());
}
-#if (QT_VERSION-0 >= 0x030200)
- if (type & (int)QSql::SystemTables) {
+ if (type & (int)TQSql::SystemTables) {
// there are no internal tables beside this one:
res.append("sqlite_master");
}
-#endif
return res;
}
-QSqlIndex QSQLite3Driver::primaryIndex(const QString &tblname) const
+TQSqlIndex TQSQLite3Driver::primaryIndex(const TQString &tblname) const
{
- QSqlRecordInfo rec(recordInfo(tblname)); // expensive :(
+ TQSqlRecordInfo rec(recordInfo(tblname)); // expensive :(
if (!isOpen())
- return QSqlIndex();
+ return TQSqlIndex();
- QSqlQuery q = createQuery();
+ TQSqlQuery q = createQuery();
q.setForwardOnly(TRUE);
- // finrst find a UNIQUE INDEX
+ // finrst find a UNITQUE INDEX
q.exec("PRAGMA index_list('" + tblname + "');");
- QString indexname;
+ TQString indexname;
while(q.next()) {
if (q.value(2).toInt()==1) {
indexname = q.value(1).toString();
@@ -432,54 +419,54 @@ QSqlIndex QSQLite3Driver::primaryIndex(const QString &tblname) const
}
}
if (indexname.isEmpty())
- return QSqlIndex();
+ return TQSqlIndex();
q.exec("PRAGMA index_info('" + indexname + "');");
- QSqlIndex index(indexname);
+ TQSqlIndex 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));
+ TQString name = q.value(2).toString();
+ TQSqlVariant::Type type = TQSqlVariant::Invalid;
+ if (rec.tqcontains(name))
+ type = rec.tqfind(name).type();
+ index.append(TQSqlField(name, type));
}
return index;
}
-QSqlRecordInfo QSQLite3Driver::recordInfo(const QString &tbl) const
+TQSqlRecordInfo TQSQLite3Driver::recordInfo(const TQString &tbl) const
{
if (!isOpen())
- return QSqlRecordInfo();
+ return TQSqlRecordInfo();
- QSqlQuery q = createQuery();
+ TQSqlQuery q = createQuery();
q.setForwardOnly(TRUE);
q.exec("SELECT * FROM " + tbl + " LIMIT 1");
return recordInfo(q);
}
-QSqlRecord QSQLite3Driver::record(const QString &tblname) const
+TQSqlRecord TQSQLite3Driver::record(const TQString &tblname) const
{
if (!isOpen())
- return QSqlRecord();
+ return TQSqlRecord();
return recordInfo(tblname).toRecord();
}
-QSqlRecord QSQLite3Driver::record(const QSqlQuery& query) const
+TQSqlRecord TQSQLite3Driver::record(const TQSqlQuery& query) const
{
if (query.isActive() && query.driver() == this) {
- QSQLite3Result* result = (QSQLite3Result*)query.result();
+ TQSQLite3Result* result = (TQSQLite3Result*)query.result();
return result->d->rInf;
}
- return QSqlRecord();
+ return TQSqlRecord();
}
-QSqlRecordInfo QSQLite3Driver::recordInfo(const QSqlQuery& query) const
+TQSqlRecordInfo TQSQLite3Driver::recordInfo(const TQSqlQuery& query) const
{
if (query.isActive() && query.driver() == this) {
- QSQLite3Result* result = (QSQLite3Result*)query.result();
- return QSqlRecordInfo(result->d->rInf);
+ TQSQLite3Result* result = (TQSQLite3Result*)query.result();
+ return TQSqlRecordInfo(result->d->rInf);
}
- return QSqlRecordInfo();
+ return TQSqlRecordInfo();
}