[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kdesvn] src/svnqt/cache: replace global static QString instances with function calls + QStringLiter
From:       Christian Ehrlicher <Ch.Ehrlicher () gmx ! de>
Date:       2016-10-09 13:16:16
Message-ID: E1btDxg-0003lJ-Qu () code ! kde ! org
[Download RAW message or body]

Git commit b1263078ccf92e54f8e0d1eaceebaef32c736a71 by Christian Ehrlicher.
Committed on 09/10/2016 at 13:14.
Pushed by chehrlic into branch 'master'.

replace global static QString instances with function calls + QStringLiteral

M  +37   -33   src/svnqt/cache/LogCache.cpp
M  +13   -16   src/svnqt/cache/ReposLog.cpp

http://commits.kde.org/kdesvn/b1263078ccf92e54f8e0d1eaceebaef32c736a71

diff --git a/src/svnqt/cache/LogCache.cpp b/src/svnqt/cache/LogCache.cpp
index 3dbb0a6..13515ad 100644
--- a/src/svnqt/cache/LogCache.cpp
+++ b/src/svnqt/cache/LogCache.cpp
@@ -36,11 +36,12 @@
 #include "svnqt/path.h"
 #include "svnqt/cache/DatabaseException.h"
 
-static const QLatin1String SQLTYPE("QSQLITE");
-static const QLatin1String SQLMAIN("logmain-logcache");
-static const QLatin1String SQLMAINTABLE("logdb");
-static const QLatin1String SQLREPOSPARAMETER("repoparameter");
-static const QLatin1String SQLSTATUS("logstatus");
+static QString SQLTYPE() { return QStringLiteral("QSQLITE"); }
+static QString SQLMAIN() { return QStringLiteral("logmain-logcache"); }
+static QString SQLMAINTABLE() { return QStringLiteral("logdb"); }
+static QString SQLTMPDB() { return QStringLiteral("tmpdb"); }
+static QString SQLREPOSPARAMETER() { return QStringLiteral("repoparameter"); }
+static QString SQLSTATUS() { return QStringLiteral("logstatus"); }
 
 namespace svn
 {
@@ -118,8 +119,8 @@ public:
     {
         const QString id = getReposId(aRepository);
 
-        static const QString s_q(QLatin1String("delete from ") + SQLREPOSPARAMETER + \
                QLatin1String(" where id = ?"));
-        static const QString r_q(QLatin1String("delete from ") + SQLMAINTABLE + \
QLatin1String(" where id = ?")); +        static const QString \
s_q(QLatin1String("delete from ") + SQLREPOSPARAMETER() + QLatin1String(" where id = \
?")); +        static const QString r_q(QLatin1String("delete from ") + \
SQLMAINTABLE() + QLatin1String(" where id = ?"));  QSqlDatabase mainDB = getMainDB();
         if (!mainDB.isValid()) {
             qWarning("Failed to open main database.");
@@ -226,14 +227,14 @@ public:
 
         _mdb.transaction();
         QSqlQuery query(_mdb);
-        QString q(QLatin1String("insert into ") + SQLMAINTABLE + QLatin1String(" \
(reposroot) VALUES('") + reposroot.path() + QLatin1String("')")); +        QString \
q(QLatin1String("insert into ") + SQLMAINTABLE() + QLatin1String(" (reposroot) \
VALUES('") + reposroot.path() + QLatin1String("')"));  
         if (!query.exec(q)) {
             return QString();
         }
 
         _mdb.commit();
-        query.prepare(s_reposSelect);
+        query.prepare(reposSelect());
         query.bindValue(0, reposroot.native());
         QString db;
         if (query.exec() && query.next()) {
@@ -243,11 +244,11 @@ public:
         }
         if (!db.isEmpty()) {
             QString fulldb = idToPath(db);
-            QSqlDatabase _db = QSqlDatabase::addDatabase(SQLTYPE, \
QStringLiteral("tmpdb")); +            QSqlDatabase _db = \
QSqlDatabase::addDatabase(SQLTYPE(), SQLTMPDB());  _db.setDatabaseName(fulldb);
             if (!checkReposDb(_db)) {
             }
-            QSqlDatabase::removeDatabase(QStringLiteral("tmpdb"));
+            QSqlDatabase::removeDatabase(SQLTMPDB());
         }
         return db;
     }
@@ -258,7 +259,7 @@ public:
             return QString();
         }
         QSqlQuery c(getMainDB());
-        c.prepare(s_reposSelect);
+        c.prepare(reposSelect());
         c.bindValue(0, reposroot.native());
 
         // only the first one
@@ -292,7 +293,7 @@ public:
             _key = QStringLiteral("%1-%2").arg(dbFile).arg(i++);
         }
         const QString fulldb = idToPath(dbFile);
-        QSqlDatabase db = QSqlDatabase::addDatabase(SQLTYPE, _key);
+        QSqlDatabase db = QSqlDatabase::addDatabase(SQLTYPE(), _key);
         db.setDatabaseName(fulldb);
         if (!checkReposDb(db)) {
             db = QSqlDatabase();
@@ -306,11 +307,11 @@ public:
     {
         if (!m_mainDB.hasLocalData()) {
             unsigned i = 0;
-            QString _key = SQLMAIN;
+            QString _key = SQLMAIN();
             while (QSqlDatabase::contains(_key)) {
-                _key = QStringLiteral("%1-%2").arg(SQLMAIN).arg(i++);
+                _key = QStringLiteral("%1-%2").arg(SQLMAIN()).arg(i++);
             }
-            QSqlDatabase db = QSqlDatabase::addDatabase(SQLTYPE, _key);
+            QSqlDatabase db = QSqlDatabase::addDatabase(SQLTYPE(), _key);
             db.setDatabaseName(m_BasePath + QLatin1String("/maindb.db"));
             if (db.open()) {
                 m_mainDB.setLocalData(new ThreadDBStore);
@@ -328,11 +329,14 @@ public:
 
     mutable QThreadStorage<ThreadDBStore *> m_mainDB;
 
-    static const QString s_reposSelect;
+    static QString reposSelect()
+    {
+        return QStringLiteral("SELECT id from ") +
+            SQLMAINTABLE() +
+            QStringLiteral(" where reposroot=? ORDER by id DESC");
+    }
 };
 
-const QString LogCacheData::s_reposSelect = QLatin1String("SELECT id from ") + \
                SQLMAINTABLE + QLatin1String(" where reposroot=? ORDER by id DESC");
-
 /*!
     \fn svn::cache::LogCache::LogCache()
  */
@@ -387,18 +391,18 @@ void LogCache::setupMainDb()
     } else {
         QStringList list = mainDB.tables();
         QSqlQuery q(mainDB);
-        if (list.indexOf(SQLSTATUS) == -1) {
+        if (list.indexOf(SQLSTATUS()) == -1) {
             mainDB.transaction();
-            if (q.exec(QLatin1String("CREATE TABLE \"") + SQLSTATUS + \
                QLatin1String("\" (\"key\" TEXT PRIMARY KEY NOT NULL, \"value\" \
                TEXT);"))) {
-                q.exec(QLatin1String("INSERT INTO \"") + SQLSTATUS + \
QLatin1String("\" (key,value) values(\"version\",\"0\");")); +            if \
(q.exec(QLatin1String("CREATE TABLE \"") + SQLSTATUS() + QLatin1String("\" (\"key\" \
TEXT PRIMARY KEY NOT NULL, \"value\" TEXT);"))) { +                \
q.exec(QLatin1String("INSERT INTO \"") + SQLSTATUS() + QLatin1String("\" (key,value) \
values(\"version\",\"0\");"));  }
             mainDB.commit();
         }
         int version = databaseVersion();
         if (version == 0) {
             mainDB.transaction();
-            if (list.indexOf(SQLMAINTABLE) == -1) {
-                q.exec(QLatin1String("CREATE TABLE IF NOT EXISTS \"") + SQLMAINTABLE \
+ QLatin1String("\" (\"reposroot\" TEXT,\"id\" INTEGER PRIMARY KEY AUTOINCREMENT NOT \
NULL);")); +            if (list.indexOf(SQLMAINTABLE()) == -1) {
+                q.exec(QLatin1String("CREATE TABLE IF NOT EXISTS \"") + \
SQLMAINTABLE() + QLatin1String("\" (\"reposroot\" TEXT,\"id\" INTEGER PRIMARY KEY \
AUTOINCREMENT NOT NULL);"));  }/* else {
                 q.exec("CREATE TABLE IF NOT EXISTS \""+QString(SQLMAINTABLE)+"new\" \
                (\"reposroot\" TEXT,\"id\" INTEGER PRIMARY KEY AUTOINCREMENT NOT \
                NULL);");
                 q.exec("insert into \""+QString(SQLMAINTABLE)+"new\" select \
\"reposroot\",\"id\" from \""+QString(SQLMAINTABLE)+"\");"); @@ -409,7 +413,7 @@ void \
LogCache::setupMainDb()  }
         if (version == 1) {
             mainDB.transaction();
-            if (!q.exec(QLatin1String("CREATE TABLE IF NOT EXISTS \"") + \
SQLREPOSPARAMETER + +            if (!q.exec(QLatin1String("CREATE TABLE IF NOT \
                EXISTS \"") + SQLREPOSPARAMETER() +
                         QLatin1String("\" (\"id\" INTEGER NOT NULL, \"parameter\" \
                TEXT, \"value\" TEXT, PRIMARY KEY(\"id\",\"parameter\"));"))) {
                 qDebug() << "Error create: " << q.lastError().text() << "(" << \
q.lastQuery() << ")";  }
@@ -426,7 +430,7 @@ void LogCache::databaseVersion(int newversion)
     if (!mainDB.isValid()) {
         return;
     }
-    static const QString _qs(QLatin1String("update \"") + SQLSTATUS + \
QLatin1String("\" SET value = ? WHERE \"key\" = \"version\"")); +    static const \
QString _qs(QLatin1String("update \"") + SQLSTATUS() + QLatin1String("\" SET value = \
? WHERE \"key\" = \"version\""));  QSqlQuery cur(mainDB);
     cur.prepare(_qs);
     cur.bindValue(0, newversion);
@@ -441,7 +445,7 @@ int LogCache::databaseVersion()const
     if (!mainDB.isValid()) {
         return -1;
     }
-    static const QString _qs(QLatin1String("select value from \"") + SQLSTATUS + \
QLatin1String("\" WHERE \"key\" = \"version\"")); +    static const QString \
_qs(QLatin1String("select value from \"") + SQLSTATUS() + QLatin1String("\" WHERE \
\"key\" = \"version\""));  QSqlQuery cur(mainDB);
     cur.prepare(_qs);
     if (!cur.exec()) {
@@ -461,9 +465,9 @@ QVariant LogCache::getRepositoryParameter(const svn::Path \
&repository, const QSt  if (!mainDB.isValid()) {
         return QVariant();
     }
-    static const QString qs(QLatin1String("select \
                \"value\",\"repoparameter\".\"parameter\" as \"key\" from \"") + \
                SQLREPOSPARAMETER +
-                            QLatin1String("\" INNER JOIN \"") + SQLMAINTABLE + \
                QLatin1String("\" ON (\"") + SQLREPOSPARAMETER +
-                            QLatin1String("\".id = \"") + SQLMAINTABLE + \
QLatin1String("\".id and \"") + SQLMAINTABLE + +    static const QString \
qs(QLatin1String("select \"value\",\"repoparameter\".\"parameter\" as \"key\" from \
\"") + SQLREPOSPARAMETER() + +                            QLatin1String("\" INNER \
JOIN \"") + SQLMAINTABLE() + QLatin1String("\" ON (\"") + SQLREPOSPARAMETER() + +     \
QLatin1String("\".id = \"") + SQLMAINTABLE() + QLatin1String("\".id and \"") + \
                SQLMAINTABLE() +
                             QLatin1String("\".reposroot = ?)  WHERE \"parameter\" = \
?;"));  QSqlQuery cur(mainDB);
     cur.prepare(qs);
@@ -489,9 +493,9 @@ bool LogCache::setRepositoryParameter(const svn::Path \
&repository, const QString  if (id.isEmpty()) {
         return false;
     }
-    static const QString qs(QLatin1String("INSERT OR REPLACE INTO \"") + \
SQLREPOSPARAMETER + +    static const QString qs(QLatin1String("INSERT OR REPLACE \
                INTO \"") + SQLREPOSPARAMETER() +
                             QLatin1String("\" (\"id\",\"parameter\",\"value\") \
                values (\"%1\",\"%2\",?);"));
-    static const QString dqs(QLatin1String("DELETE FROM \"") + SQLREPOSPARAMETER +
+    static const QString dqs(QLatin1String("DELETE FROM \"") + SQLREPOSPARAMETER() +
                              QLatin1String("\" WHERE \"id\"=? and \"parameter\" = \
?"));  mainDB.transaction();
     QSqlQuery cur(mainDB);
@@ -548,7 +552,7 @@ QSqlDatabase  svn::cache::LogCache::reposDb(const QString \
                &aRepository)
  */
 QStringList svn::cache::LogCache::cachedRepositories()const
 {
-    static const QString s_q(QLatin1String("select \"reposroot\" from ") + \
SQLMAINTABLE + QLatin1String(" order by reposroot")); +    static const QString \
s_q(QLatin1String("select \"reposroot\" from ") + SQLMAINTABLE() + QLatin1String(" \
order by reposroot"));  QSqlDatabase mainDB = m_CacheData->getMainDB();
     QStringList _res;
     if (!mainDB.isValid()) {
diff --git a/src/svnqt/cache/ReposLog.cpp b/src/svnqt/cache/ReposLog.cpp
index e2bb27e..0273d7a 100644
--- a/src/svnqt/cache/ReposLog.cpp
+++ b/src/svnqt/cache/ReposLog.cpp
@@ -317,19 +317,9 @@ bool svn::cache::ReposLog::simpleLog(LogEntriesMap &target, \
const svn::Revision  if (start == svn::Revision::HEAD) {
         start = latestCachedRev();
     }
-    QString sItems(QStringLiteral("select changeditem,action,copyfrom,copyfromrev \
from changeditems where revision=?"));  
-    for (int i = 0; i < exclude.size(); ++i) {
-        sItems += QLatin1String(" and changeditem not like '") + exclude[i] + \
                QLatin1String("%'");
-    }
-
-    QSqlQuery bcount(QString(), m_Database);
+    QSqlQuery bcount(m_Database);
     bcount.prepare(QStringLiteral("select count(*) from logentries where revision<=? \
                and revision>=?"));
-
-    QSqlQuery bcur(QString(), m_Database);
-
-    QSqlQuery cur(QString(), m_Database);
-
     bcount.bindValue(0, Q_LLONG(end.revnum()));
     bcount.bindValue(1, Q_LLONG(start.revnum()));
     if (!bcount.exec()) {
@@ -342,6 +332,7 @@ bool svn::cache::ReposLog::simpleLog(LogEntriesMap &target, const \
svn::Revision  return false;
     }
 
+    QSqlQuery bcur(m_Database);
     bcur.setForwardOnly(true);
     bcur.prepare(QStringLiteral("select revision,author,date,message from logentries \
where revision<=? and revision>=?"));  bcur.bindValue(0, Q_LLONG(end.revnum()));
@@ -351,16 +342,22 @@ bool svn::cache::ReposLog::simpleLog(LogEntriesMap &target, \
                const svn::Revision
         throw svn::cache::DatabaseException(QLatin1String("Could not retrieve \
values: ") + bcur.lastError().text());  return false;
     }
-    Q_LLONG revision;
+
+    QString sItems(QStringLiteral("select changeditem,action,copyfrom,copyfromrev \
from changeditems where revision=?")); +    for (int i = 0; i < exclude.size(); ++i) \
{ +        sItems += QLatin1String(" and changeditem not like '") + exclude[i] + \
QLatin1String("%'"); +    }
+    QSqlQuery cur(m_Database);
+    cur.setForwardOnly(true);
+    cur.prepare(sItems);
+
     while (bcur.next()) {
-        cur.setForwardOnly(true);
-        cur.prepare(sItems);
-        revision = bcur.value(0).toLongLong();
+        const Q_LLONG revision = bcur.value(0).toLongLong();
         cur.bindValue(0, revision);
 
         if (!cur.exec()) {
           //qDebug() << cur.lastError().text();
-          throw svn::cache::DatabaseException(QString(QStringLiteral("Could not \
retrieve revision values: %1, %2")) +          throw \
svn::cache::DatabaseException(QStringLiteral("Could not retrieve revision values: %1, \
                %2")
                                               .arg(cur.lastError().text(),
                                                    \
cur.lastError().nativeErrorCode()));  return false;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic