changeset 31:bf3dce7fedcb

Remove all references to QDebug
author Tom Fredrik Blenning Klaussen <bfg@blenning.no>
date Thu, 06 Sep 2012 19:14:58 +0200
parents 1072257d2bab
children c978d4a6514d
files CMakeLists.txt DBCache.hpp DataController.cpp Exception/SQLException.cpp Exception/SQLException.hpp FileDBLink.cpp RBTree.hpp SqliteDBLink.cpp TestBitDecoder.cpp TestHuffmanString.cpp UniqueString.hpp
diffstat 11 files changed, 53 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/CMakeLists.txt	Thu Sep 06 18:39:01 2012 +0200
+++ b/CMakeLists.txt	Thu Sep 06 19:14:58 2012 +0200
@@ -32,6 +32,7 @@
 	HuffmanSet.cpp
 	EditDistance.cpp
 	Exception/IOException.cpp
+	Exception/SQLException.cpp
 	FileDBLink.cpp
 	SqliteDBLink.cpp
 	MemoryDBLink.cpp
@@ -85,8 +86,7 @@
 ADD_TEST(TestEditDistance TestEditDistance)
 TARGET_LINK_LIBRARIES(TestEditDistance ${QT_LIBRARIES} ${Boost_LIBRARIES})
 
-#ADD_EXECUTABLE(TestDBCache TestDBCache.cpp ${TEST_SOURCES})
-ADD_EXECUTABLE(TestDBCache TestDBCache.cpp)
+ADD_EXECUTABLE(TestDBCache TestDBCache.cpp ${TEST_SOURCES})
 ADD_TEST(TestDBCache TestDBCache)
 TARGET_LINK_LIBRARIES(TestDBCache ${QT_LIBRARIES} ${Boost_LIBRARIES})
 
--- a/DBCache.hpp	Thu Sep 06 18:39:01 2012 +0200
+++ b/DBCache.hpp	Thu Sep 06 19:14:58 2012 +0200
@@ -6,8 +6,9 @@
 #include <QtSql/QSqlError>
 #include <QtSql/QSqlRecord>
 
-#include <QtCore/QDebug>
+
 #include <QtCore/QStringList>
+#include <QtCore/QVariant>
 #include <cassert>
 #include "OrderedPair.hpp"
 
@@ -15,6 +16,7 @@
 
 #include "ThreadSafeLookup.hpp"
 #include "UniqueString.hpp"
+#include "Exception/SQLException.hpp"
 
 
 template<typename T>
@@ -253,8 +255,7 @@
       query.exec(createQuery);
     }
     if (!db.tables().contains(dictName)) {
-      qDebug()<<"No database";
-      exit(1);
+      throw SQLException("No databaase");
     }
     if (memoryMapped) {
       QString keyFields = SQLGenerator<Key>::fieldName("key");
@@ -262,7 +263,7 @@
       QString repopulateQuery = QString("SELECT %1, %2 FROM %3;").arg(keyFields).arg(valueFields).arg(dictName);
       QSqlQuery query(db);
       if (!query.exec(repopulateQuery)) {
-	qDebug() << query.lastError() << repopulateQuery;
+	throw SQLException(query);
       }
       while (query.next()) {
 	Key key = *SQLGenerator<Key>::extract(query, "key");
@@ -289,7 +290,7 @@
     }
     SQLGenerator<Value>::bindValues(insertQuery, values, "value");
     if (!insertQuery.exec()) {
-      qDebug() << insertQuery.lastError() << insertQuery.lastQuery();
+      throw SQLException(insertQuery);
     }
     insertQuery.finish();
     unsyncedKeys.clear();
@@ -324,7 +325,7 @@
       query.prepare(queryString);
       SQLGenerator<Key>::bindValue(query, key, "key");
       if (!query.exec()) {
-	qDebug() << query.lastError() << queryString;
+	throw SQLException(query);
       }
       query.next();
       return SQLGenerator<Value>::extract(query, "value");
@@ -344,7 +345,7 @@
       SQLGenerator<Key>::bindValue(insertQuery, key, "key");
       SQLGenerator<Value>::bindValue(insertQuery, value, "value");
       if (!insertQuery.exec()) {
-	qDebug() << insertQuery.lastError() << insertQuery.lastQuery();
+	throw SQLException(insertQuery);
       }
       insertQuery.finish();
     }
--- a/DataController.cpp	Thu Sep 06 18:39:01 2012 +0200
+++ b/DataController.cpp	Thu Sep 06 19:14:58 2012 +0200
@@ -8,7 +8,7 @@
 
 #include <QtCore/QCryptographicHash>
 #include <QtCore/QDateTime>
-#include <QtCore/QDebug>
+
 #include <QtCore/QDir>
 #include <QtCore/QTimer>
 #include <QtCore/QUrl>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Exception/SQLException.cpp	Thu Sep 06 19:14:58 2012 +0200
@@ -0,0 +1,13 @@
+#include "SQLException.hpp"
+
+#include <QtSql/QSqlQuery>
+#include <QtSql/QSqlError>
+
+SQLException::SQLException(const QString& errorMsg) : Exception(errorMsg)
+{
+}
+
+SQLException::SQLException(const QSqlQuery& errorQuery) :
+  Exception(errorQuery.lastError().text() + ":" + errorQuery.lastQuery())
+{
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Exception/SQLException.hpp	Thu Sep 06 19:14:58 2012 +0200
@@ -0,0 +1,13 @@
+#ifndef SQLEXCEPTION_HPP
+#define SQLEXCEPTION_HPP
+
+#include "Exception.hpp"
+class QSqlQuery;
+
+class SQLException : public Exception {
+public:
+  SQLException(const string_t& errMsg);
+  SQLException(const QSqlQuery& error);
+};
+
+#endif //IOEXCEPTION_HPP
--- a/FileDBLink.cpp	Thu Sep 06 18:39:01 2012 +0200
+++ b/FileDBLink.cpp	Thu Sep 06 19:14:58 2012 +0200
@@ -2,7 +2,7 @@
 #include "FileDBLink.hpp"
 #include "Exception/PermissionException.hpp"
 
-#include <QtCore/QDebug>
+
 #include <QtCore/QtConcurrentMap>
 
 #include <boost/bind.hpp>
--- a/RBTree.hpp	Thu Sep 06 18:39:01 2012 +0200
+++ b/RBTree.hpp	Thu Sep 06 19:14:58 2012 +0200
@@ -5,7 +5,7 @@
 #include <cmath>
 #include "Exception/ValueExistsException.hpp"
 
-#include <QtCore/QDebug>
+
 
 #define CONSISTENCY_CHECKING 1
 
--- a/SqliteDBLink.cpp	Thu Sep 06 18:39:01 2012 +0200
+++ b/SqliteDBLink.cpp	Thu Sep 06 19:14:58 2012 +0200
@@ -1,12 +1,15 @@
 #include "SqliteDBLink.hpp"
 
 #include <QtCore/QStringList>
-#include <QtCore/QDebug>
+#include <QtCore/QVariant>
+
 
 #include <QtSql/QSqlQuery>
 #include <QtSql/QSqlError>
 #include <QtSql/QSqlRecord>
 
+#include "Exception/SQLException.hpp"
+
 #include <cassert>
 
 SqliteDBLink::SqliteDBLink(const QString& dbPath)
@@ -20,8 +23,7 @@
     query.exec("CREATE TABLE files(path VARCHAR PRIMARY KEY ASC, size INTEGER, mtime TEXT, checksum TEXT);");
   }
   if (!query.exec(QString("SELECT * FROM files;"))) {
-    qDebug()<<"No database";
-    exit(1);
+    throw SQLException("No database");
   }
 
 }
@@ -37,7 +39,7 @@
   query.prepare("SELECT path FROM files WHERE path = :path;");
   query.bindValue(":path", path);
   if (!query.exec()) {
-    qDebug() << path << "::" << query.lastQuery() << "::" << query.lastError().text();
+    throw SQLException(query);
   }
   return query.last();
 }
@@ -48,7 +50,7 @@
   query.prepare("SELECT mtime FROM files WHERE path = :path;");
   query.bindValue(":path", path);
   if (!query.exec()) {
-    qDebug() << path << "::" << query.lastQuery() << "::" << query.lastError().text();
+    throw SQLException(query);
   }
   if (query.next()) {
     int dateIndex = query.record().indexOf("mtime");
@@ -77,7 +79,7 @@
   query.bindValue(":mtime", dbinfo.mtime());
   query.bindValue(":checksum", dbinfo.checksum());
   if (!query.exec()) {
-    qDebug() << dbinfo.path() << "::" << query.lastQuery() << "::" << query.lastError().text();
+    throw SQLException(query);
   }
   return true;
 }
@@ -96,7 +98,7 @@
   query.bindValue(":mtime", dbinfo.mtime());
   query.bindValue(":checksum", dbinfo.checksum());
   if (!query.exec()) {
-    qDebug() << query.lastError().text();
+    throw SQLException(query);
   }
 }
 
@@ -135,8 +137,7 @@
   }
 
   if (!query.exec()) {
-    qDebug() << prefix << "::" << query.lastQuery() << "::" << query.lastError().text();
-    abort();
+    throw SQLException(query);
   }
 
   int pathIndex = query.record().indexOf("path");
@@ -162,7 +163,7 @@
   query.prepare("DELETE FROM files WHERE path = :path");
   query.bindValue(":path", path);
   if (!query.exec()) {
-    qDebug() << path << "::" << query.lastQuery() << "::" << query.lastError().text();
+    throw SQLException(query);
   }
 }
 
--- a/TestBitDecoder.cpp	Thu Sep 06 18:39:01 2012 +0200
+++ b/TestBitDecoder.cpp	Thu Sep 06 19:14:58 2012 +0200
@@ -2,7 +2,7 @@
 #include "TestFramework.hpp"
 
 #include "Exception/InvalidDataException.hpp"
-#include <QtCore/QDebug>
+
 
 QBitArray bitsFromString(const QString& str)
 {
--- a/TestHuffmanString.cpp	Thu Sep 06 18:39:01 2012 +0200
+++ b/TestHuffmanString.cpp	Thu Sep 06 19:14:58 2012 +0200
@@ -1,7 +1,7 @@
 #include "HuffmanString.hpp"
 #include "TestFramework.hpp"
 
-#include <QtCore/QDebug>
+
 
 BOOST_AUTO_TEST_CASE( TestSimple )
 {
--- a/UniqueString.hpp	Thu Sep 06 18:39:01 2012 +0200
+++ b/UniqueString.hpp	Thu Sep 06 19:14:58 2012 +0200
@@ -23,7 +23,7 @@
 #include "RBTree.hpp"
 #include <QtCore/QString>
 #include <QtCore/QStringList>
-#include <QtCore/QDebug>
+
 
 class UniqueString
 {