diff options
Diffstat (limited to 'src/svnqt/cache/LogCache.cpp')
-rw-r--r-- | src/svnqt/cache/LogCache.cpp | 266 |
1 files changed, 70 insertions, 196 deletions
diff --git a/src/svnqt/cache/LogCache.cpp b/src/svnqt/cache/LogCache.cpp index 6356c6f..15fe04e 100644 --- a/src/svnqt/cache/LogCache.cpp +++ b/src/svnqt/cache/LogCache.cpp @@ -1,31 +1,23 @@ #include "LogCache.hpp" -#include <qdir.h> -#include <qsql.h> -#include <qsqldatabase.h> -#if QT_VERSION < 0x040000 -#include <qthreadstorage.h> -#else -#include <QMutex> -#include <QThreadStorage> -#include <QSqlError> -#include <QSqlQuery> -#include <QVariant> -#endif -#include <qmap.h> +#include <tqdir.h> +#include <tqsql.h> +#include <tqsqldatabase.h> +#include <tqthreadstorage.h> +#include <tqmap.h> #include "svnqt/path.hpp" #include "svnqt/cache/DatabaseException.hpp" -#ifndef NO_SQLITE3 +#ifndef NO_STQLITE3 #include "sqlite3/qsql_sqlite3.h" #define SQLTYPE "QSQLITE3" #else #define SQLTYPE "QSQLITE" #endif -#define SQLMAIN "logmain-logcache" -#define SQLMAINTABLE "logdb" +#define STQLMAIN "logmain-logcache" +#define STQLMAINTABLE "logdb" namespace svn { namespace cache { @@ -36,39 +28,27 @@ class ThreadDBStore { public: ThreadDBStore(){ -#if QT_VERSION < 0x040000 m_DB=0; -#else - m_DB=QSqlDatabase(); -#endif } ~ThreadDBStore(){ -#if QT_VERSION < 0x040000 m_DB=0; -#else - m_DB=QSqlDatabase(); -#endif - QSqlDatabase::removeDatabase(key); - QMap<QString,QString>::Iterator it; + TQSqlDatabase::removeDatabase(key); + TQMap<TQString,TQString>::Iterator it; for (it=reposCacheNames.begin();it!=reposCacheNames.end();++it) { -#if QT_VERSION < 0x040000 - QSqlDatabase::removeDatabase(it.data()); -#else - QSqlDatabase::removeDatabase(it.value()); -#endif + TQSqlDatabase::removeDatabase(it.data()); } } - QDataBase m_DB; - QString key; - QMap<QString,QString> reposCacheNames; + TQDataBase m_DB; + TQString key; + TQMap<TQString,TQString> reposCacheNames; }; class LogCacheData { protected: - QMutex m_singleDbMutex; + TQMutex m_singleDbMutex; public: LogCacheData(){} @@ -78,97 +58,52 @@ public: } } - bool checkReposDb(QDataBase aDb) + bool checkReposDb(TQDataBase aDb) { -#if QT_VERSION < 0x040000 if (!aDb) { return false; } if (!aDb->open()) { return false; } -#else - if (!aDb.open()) { - return false; - } -#endif - QSqlQuery _q(QString::null, aDb); -#if QT_VERSION < 0x040000 - QStringList list = aDb->tables(); -#else - QStringList list = aDb.tables(); -#endif + TQSqlQuery _q(TQString(), aDb); + TQStringList list = aDb->tables(); -#if QT_VERSION < 0x040000 - if (list.find("logentries")==list.end()) { + if (list.tqfind("logentries")==list.end()) { aDb->transaction(); -#else - if (list.indexOf("logentries")==-1) { - aDb.transaction(); -#endif - _q.exec("CREATE TABLE \"logentries\" (\"revision\" INTEGER UNIQUE,\"date\" INTEGER,\"author\" TEXT, \"message\" TEXT)"); -#if QT_VERSION < 0x040000 + _q.exec("CREATE TABLE \"logentries\" (\"revision\" INTEGER UNITQUE,\"date\" INTEGER,\"author\" TEXT, \"message\" TEXT)"); aDb->commit(); -#else - aDb.commit(); -#endif } -#if QT_VERSION < 0x040000 - if (list.find("changeditems")==list.end()) { + if (list.tqfind("changeditems")==list.end()) { aDb->transaction(); -#else - if (list.indexOf("changeditems")==-1) { - aDb.transaction(); -#endif _q.exec("CREATE TABLE \"changeditems\" (\"revision\" INTEGER,\"changeditem\" TEXT,\"action\" TEXT,\"copyfrom\" TEXT,\"copyfromrev\" INTEGER, PRIMARY KEY(revision,changeditem,action))"); -#if QT_VERSION < 0x040000 aDb->commit(); -#else - aDb.commit(); -#endif } -#if QT_VERSION < 0x040000 list = aDb->tables(); - if (list.find("logentries")==list.end() || list.find("changeditems")==list.end()) { -#else - list = aDb.tables(); - if (list.indexOf("logentries")==-1 || list.indexOf("changeditems")==-1) { -#endif + if (list.tqfind("logentries")==list.end() || list.tqfind("changeditems")==list.end()) { return false; } return true; } - QString createReposDB(const svn::Path&reposroot) { - QMutexLocker locker( &m_singleDbMutex ); + TQString createReposDB(const svn::Path&reposroot) { + TQMutexLocker locker( &m_singleDbMutex ); - QDataBase _mdb = getMainDB(); + TQDataBase _mdb = getMainDB(); - QSqlQuery query1(QString::null,_mdb); - QString q("insert into "+QString(SQLMAINTABLE)+" (reposroot) VALUES('"+reposroot+"')"); -#if QT_VERSION < 0x040000 + TQSqlQuery query1(TQString(),_mdb); + TQString q("insert into "+TQString(STQLMAINTABLE)+" (reposroot) VALUES('"+reposroot+"')"); _mdb->transaction(); -#else - _mdb.transaction(); -#endif query1.exec(q); -#if QT_VERSION < 0x040000 _mdb->commit(); -#else - _mdb.commit(); -#endif - QSqlQuery query(QString::null,_mdb); + TQSqlQuery query(TQString(),_mdb); query.prepare(s_reposSelect); query.bindValue(0,reposroot.native()); query.exec(); - QString db; -#if QT_VERSION < 0x040000 - if (query.lastError().type()==QSqlError::None && query.next()) { -#else - if (query.lastError().type()==QSqlError::NoError && query.next()) { -#endif + TQString db; + if (query.lastError().type()==TQSqlError::None && query.next()) { db = query.value(0).toString(); } else { @@ -176,89 +111,62 @@ public: query.lastQuery().TOUTF8().data()); } if (!db.isEmpty()) { - QString fulldb = m_BasePath+"/"+db+".db"; - QDataBase _db = QSqlDatabase::addDatabase(SQLTYPE,"tmpdb"); -#if QT_VERSION < 0x040000 + TQString fulldb = m_BasePath+"/"+db+".db"; + TQDataBase _db = TQSqlDatabase::addDatabase(SQLTYPE,"tmpdb"); _db->setDatabaseName(fulldb); -#else - _db.setDatabaseName(fulldb); -#endif if (!checkReposDb(_db)) { } - QSqlDatabase::removeDatabase("tmpdb"); + TQSqlDatabase::removeDatabase("tmpdb"); } return db; } - QDataBase getReposDB(const svn::Path&reposroot) { -#if QT_VERSION < 0x040000 + TQDataBase getReposDB(const svn::Path&reposroot) { if (!getMainDB()) { return 0; -#else - if (!getMainDB().isValid()) { - return QDataBase(); -#endif } bool checkDone = false; // make sure path is correct eg. without traling slashes. - QString dbFile; - QSqlQuery c(QString::null,getMainDB()); + TQString dbFile; + TQSqlQuery c(TQString(),getMainDB()); c.prepare(s_reposSelect); c.bindValue(0,reposroot.native()); c.exec(); -#if QT_VERSION < 0x040000 //qDebug("Check for path: "+reposroot.native()); -#endif // only the first one if ( c.next() ) { -#if QT_VERSION < 0x040000 /* qDebug( c.value(0).toString() + ": " + c.value(0).toString() );*/ -#endif dbFile = c.value(0).toString(); } if (dbFile.isEmpty()) { dbFile = createReposDB(reposroot); if (dbFile.isEmpty()) { -#if QT_VERSION < 0x040000 return 0; -#else - return QSqlDatabase(); -#endif } checkDone=true; } - if (m_mainDB.localData()->reposCacheNames.find(dbFile)!=m_mainDB.localData()->reposCacheNames.end()) { - return QSqlDatabase::database(m_mainDB.localData()->reposCacheNames[dbFile]); + if (m_mainDB.localData()->reposCacheNames.tqfind(dbFile)!=m_mainDB.localData()->reposCacheNames.end()) { + return TQSqlDatabase::database(m_mainDB.localData()->reposCacheNames[dbFile]); } int i = 0; - QString _key = dbFile; - while (QSqlDatabase::contains(_key)) { - _key = QString("%1-%2").arg(dbFile).arg(i++); + TQString _key = dbFile; + while (TQSqlDatabase::tqcontains(_key)) { + _key = TQString("%1-%2").tqarg(dbFile).tqarg(i++); } // qDebug("The repository key is now: %s",_key.TOUTF8().data()); - QDataBase _db = QSqlDatabase::addDatabase(SQLTYPE,_key); -#if QT_VERSION < 0x040000 + TQDataBase _db = TQSqlDatabase::addDatabase(SQLTYPE,_key); if (!_db) { return 0; } -#endif - QString fulldb = m_BasePath+"/"+dbFile+".db"; -#if QT_VERSION < 0x040000 + TQString fulldb = m_BasePath+"/"+dbFile+".db"; _db->setDatabaseName(fulldb); -#else - _db.setDatabaseName(fulldb); -#endif // qDebug("try database open %s",fulldb.TOUTF8().data()); if (!checkReposDb(_db)) { qDebug("no DB opened"); -#if QT_VERSION < 0x040000 _db = 0; -#else - _db = QSqlDatabase(); -#endif } else { qDebug("Insert into map"); m_mainDB.localData()->reposCacheNames[dbFile]=_key; @@ -266,27 +174,20 @@ public: return _db; } - QDataBase getMainDB()const + TQDataBase getMainDB()const { if (!m_mainDB.hasLocalData()) { unsigned i=0; - QString _key = SQLMAIN; - while (QSqlDatabase::contains(_key)) { - _key.sprintf("%s-%i",SQLMAIN,i++); + TQString _key = STQLMAIN; + while (TQSqlDatabase::tqcontains(_key)) { + _key.sprintf("%s-%i",STQLMAIN,i++); } qDebug("The key is now: %s",_key.TOUTF8().data()); - QDataBase db = QSqlDatabase::addDatabase(SQLTYPE,_key); -#if QT_VERSION < 0x040000 + TQDataBase db = TQSqlDatabase::addDatabase(SQLTYPE,_key); db->setDatabaseName(m_BasePath+"/maindb.db"); if (!db->open()) { -#else - db.setDatabaseName(m_BasePath+"/maindb.db"); - if (!db.open()) { -#endif -#if QT_VERSION < 0x040000 qWarning("Failed to open main database: " + db->lastError().text()); -#endif } else { m_mainDB.setLocalData(new ThreadDBStore); m_mainDB.localData()->key = _key; @@ -296,41 +197,37 @@ public: if (m_mainDB.hasLocalData()) { return m_mainDB.localData()->m_DB; } else { -#if QT_VERSION < 0x040000 return 0; -#else - return QSqlDatabase(); -#endif } } - QString m_BasePath; + TQString m_BasePath; - mutable QThreadStorage<ThreadDBStore*> m_mainDB; + mutable TQThreadStorage<ThreadDBStore*> m_mainDB; - static const QString s_reposSelect; + static const TQString s_reposSelect; }; -QString LogCache::s_CACHE_FOLDER="logcache"; -const QString LogCacheData::s_reposSelect=QString("SELECT id from ")+QString(SQLMAINTABLE)+QString(" where reposroot=? ORDER by id DESC"); +TQString LogCache::s_CACHE_FOLDER="logcache"; +const TQString LogCacheData::s_reposSelect=TQString("SELECT id from ")+TQString(STQLMAINTABLE)+TQString(" where reposroot=? ORDER by id DESC"); /*! \fn svn::cache::LogCache::LogCache() */ LogCache::LogCache() { - m_BasePath = QDir::HOMEDIR()+"/.svnqt"; + m_BasePath = TQDir::HOMEDIR()+"/.svnqt"; setupCachePath(); } -LogCache::LogCache(const QString&aBasePath) +LogCache::LogCache(const TQString&aBasePath) { if (mSelf) { delete mSelf; } mSelf=this; if (aBasePath.isEmpty()) { - m_BasePath=QDir::HOMEDIR()+"/.svnqt"; + m_BasePath=TQDir::HOMEDIR()+"/.svnqt"; } else { m_BasePath=aBasePath; } @@ -349,7 +246,7 @@ void LogCache::setupCachePath() { m_CacheData = new LogCacheData; m_CacheData->m_BasePath=m_BasePath; - QDir d; + TQDir d; if (!d.exists(m_BasePath)) { d.mkdir(m_BasePath); } @@ -366,35 +263,20 @@ void LogCache::setupCachePath() void LogCache::setupMainDb() { #ifndef NO_SQLITE3 - if (!QSqlDatabase::isDriverAvailable(SQLTYPE)) { - QSqlDatabase::registerSqlDriver(SQLTYPE,new QSqlDriverCreator<QSQLite3Driver>); + if (!TQSqlDatabase::isDriverAvailable(SQLTYPE)) { + TQSqlDatabase::registerSqlDriver(SQLTYPE,new TQSqlDriverCreator<TQSQLite3Driver>); } #endif - QDataBase mainDB = m_CacheData->getMainDB(); -#if QT_VERSION < 0x040000 + TQDataBase mainDB = m_CacheData->getMainDB(); if (!mainDB || !mainDB->open()) { qWarning("Failed to open main database: " + (mainDB?mainDB->lastError().text():"No database object.")); -#else - if (!mainDB.isValid()) { - qWarning("Failed to open main database."); -#endif } else { - QSqlQuery q(QString::null, mainDB); -#if QT_VERSION < 0x040000 + TQSqlQuery q(TQString(), mainDB); mainDB->transaction(); -#else - mainDB.transaction(); -#endif - if (!q.exec("CREATE TABLE IF NOT EXISTS \""+QString(SQLMAINTABLE)+"\" (\"reposroot\" TEXT,\"id\" INTEGER PRIMARY KEY NOT NULL);")) { -#if QT_VERSION < 0x040000 + if (!q.exec("CREATE TABLE IF NOT EXISTS \""+TQString(STQLMAINTABLE)+"\" (\"reposroot\" TEXT,\"id\" INTEGER PRIMARY KEY NOT NULL);")) { qWarning("Failed create main database: " + mainDB->lastError().text()); -#endif } -#if QT_VERSION < 0x040000 mainDB->commit(); -#else - mainDB.commit(); -#endif } } @@ -417,7 +299,7 @@ svn::cache::LogCache* svn::cache::LogCache::self() /*! \fn svn::cache::LogCache::reposDb() */ -QDataBase svn::cache::LogCache::reposDb(const QString&aRepository) +TQDataBase svn::cache::LogCache::reposDb(const TQString&aRepository) { // qDebug("reposDB"); return m_CacheData->getReposDB(aRepository); @@ -427,24 +309,20 @@ QDataBase svn::cache::LogCache::reposDb(const QString&aRepository) /*! \fn svn::cache::LogCache::cachedRepositories()const */ -QStringList svn::cache::LogCache::cachedRepositories()const +TQStringList svn::cache::LogCache::cachedRepositories()const { - static QString s_q(QString("select \"reposroot\" from ")+QString(SQLMAINTABLE)+QString("order by reposroot")); - QDataBase mainDB = m_CacheData->getMainDB(); - QStringList _res; -#if QT_VERSION < 0x040000 + static TQString s_q(TQString("select \"reposroot\" from ")+TQString(STQLMAINTABLE)+TQString("order by reposroot")); + TQDataBase mainDB = m_CacheData->getMainDB(); + TQStringList _res; if (!mainDB || !mainDB->open()) { -#else - if (!mainDB.isValid()) { -#endif qWarning("Failed to open main database."); return _res; } - QSqlQuery cur(QString::null,mainDB); + TQSqlQuery cur(TQString(),mainDB); cur.prepare(s_q); if (!cur.exec()) { qDebug(cur.lastError().text().TOUTF8().data()); - throw svn::cache::DatabaseException(QString("Could not retrieve values: ")+cur.lastError().text()); + throw svn::cache::DatabaseException(TQString("Could not retrieve values: ")+cur.lastError().text()); return _res; } while (cur.next()) { @@ -456,12 +334,8 @@ QStringList svn::cache::LogCache::cachedRepositories()const bool svn::cache::LogCache::valid()const { - QDataBase mainDB = m_CacheData->getMainDB(); -#if QT_VERSION < 0x040000 + TQDataBase mainDB = m_CacheData->getMainDB(); if (!mainDB || !mainDB->open()) { -#else - if (!mainDB.isValid()) { -#endif return false; } return true; |