From 5d0a54ce8b607e570c034a8fff347c35d908b403 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Wed, 23 May 2012 12:18:42 +0200 Subject: [PATCH] * Moved TomahawkSqlQuery's implementation into a separate file. --- src/libtomahawk/CMakeLists.txt | 2 +- src/libtomahawk/database/TomahawkSqlQuery.cpp | 76 +++++++++++++++++++ src/libtomahawk/database/TomahawkSqlQuery.h | 51 ++----------- 3 files changed, 83 insertions(+), 46 deletions(-) create mode 100644 src/libtomahawk/database/TomahawkSqlQuery.cpp diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index 1e5029426..4a1f0c049 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -197,7 +197,6 @@ set( libSources audio/AudioEngine.cpp - database/Database.cpp database/FuzzyIndex.cpp database/DatabaseCollection.cpp @@ -250,6 +249,7 @@ set( libSources database/DatabaseCommand_TrackAttributes.cpp database/DatabaseCommand_SetTrackAttributes.cpp database/Database.cpp + database/TomahawkSqlQuery.cpp infosystem/InfoSystem.cpp infosystem/InfoSystemCache.cpp diff --git a/src/libtomahawk/database/TomahawkSqlQuery.cpp b/src/libtomahawk/database/TomahawkSqlQuery.cpp new file mode 100644 index 000000000..faf832625 --- /dev/null +++ b/src/libtomahawk/database/TomahawkSqlQuery.cpp @@ -0,0 +1,76 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Christian Muehlhaeuser + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#include "database/TomahawkSqlQuery.h" + +#include "utils/Logger.h" + +#include +#include + +#define QUERY_THRESHOLD 60 + + +TomahawkSqlQuery::TomahawkSqlQuery() + : QSqlQuery() +{ +} + + +TomahawkSqlQuery::TomahawkSqlQuery( const QSqlDatabase& db ) + : QSqlQuery( db ) +{ +} + + +bool +TomahawkSqlQuery::exec( const QString& query ) +{ + prepare( query ); + return exec(); +} + + +bool +TomahawkSqlQuery::exec() +{ + QTime t; + t.start(); + + bool ret = QSqlQuery::exec(); + if ( !ret ) + showError(); + + int e = t.elapsed(); + if ( e >= QUERY_THRESHOLD ) + tLog() << "TomahawkSqlQuery (" << lastQuery() << ") finished in" << t.elapsed() << "ms"; + + return ret; +} + + +void +TomahawkSqlQuery::showError() +{ + tLog() << "\n" << "*** DATABASE ERROR ***" << "\n" + << this->lastQuery() << "\n" + << "boundValues:" << this->boundValues() << "\n" + << this->lastError().text() << "\n" + ; + Q_ASSERT( false ); +} diff --git a/src/libtomahawk/database/TomahawkSqlQuery.h b/src/libtomahawk/database/TomahawkSqlQuery.h index b88d56eb8..ef078f612 100644 --- a/src/libtomahawk/database/TomahawkSqlQuery.h +++ b/src/libtomahawk/database/TomahawkSqlQuery.h @@ -18,62 +18,23 @@ #ifndef TOMAHAWKSQLQUERY_H #define TOMAHAWKSQLQUERY_H + // subclass QSqlQuery so that it prints the error msg if a query fails #include -#include -#include - -#include "utils/Logger.h" - -#define TOMAHAWK_QUERY_THRESHOLD 60 class TomahawkSqlQuery : public QSqlQuery { public: + TomahawkSqlQuery(); + TomahawkSqlQuery( const QSqlDatabase& db ); - TomahawkSqlQuery() - : QSqlQuery() - {} - - TomahawkSqlQuery( const QSqlDatabase& db ) - : QSqlQuery( db ) - {} - - bool exec( const QString& query ) - { - prepare( query ); - - return exec(); - } - - bool exec() - { - QTime t; - t.start(); - - bool ret = QSqlQuery::exec(); - if( !ret ) - showError(); - - int e = t.elapsed(); - if ( e >= TOMAHAWK_QUERY_THRESHOLD ) - tLog( LOGVERBOSE ) << "TomahawkSqlQuery (" << lastQuery() << ") finished in" << t.elapsed() << "ms"; - - return ret; - } + bool exec( const QString& query ); + bool exec(); private: - void showError() - { - tLog() << "\n" << "*** DATABASE ERROR ***" << "\n" - << this->lastQuery() << "\n" - << "boundValues:" << this->boundValues() << "\n" - << this->lastError().text() << "\n" - ; - Q_ASSERT( false ); - } + void showError(); }; #endif // TOMAHAWKSQLQUERY_H