diff options
author | Uwe Klotz <uwe_klotz@web.de> | 2017-05-28 11:50:50 +0200 |
---|---|---|
committer | Uwe Klotz <uwe_klotz@web.de> | 2017-06-12 07:30:17 +0200 |
commit | 31563434b6c15cba45b6ae4f3ef8b50e702b4ad3 (patch) | |
tree | afb875ca1b4b9fa3473b043fb93b53e432aeda19 /src | |
parent | c57466ba8b47009a1d2fd5043c0beb37dfc8825b (diff) |
Avoid passing QSqlDatabase by mutable reference
...otherwise someone would be able to replace the implicitly shared
instance behind it!
Diffstat (limited to 'src')
-rw-r--r-- | src/library/dao/analysisdao.cpp | 2 | ||||
-rw-r--r-- | src/library/dao/analysisdao.h | 2 | ||||
-rw-r--r-- | src/library/dao/cuedao.cpp | 2 | ||||
-rw-r--r-- | src/library/dao/cuedao.h | 4 | ||||
-rw-r--r-- | src/library/dao/directorydao.cpp | 2 | ||||
-rw-r--r-- | src/library/dao/directorydao.h | 4 | ||||
-rw-r--r-- | src/library/dao/libraryhashdao.cpp | 2 | ||||
-rw-r--r-- | src/library/dao/libraryhashdao.h | 4 | ||||
-rw-r--r-- | src/library/dao/playlistdao.cpp | 2 | ||||
-rw-r--r-- | src/library/dao/playlistdao.h | 4 | ||||
-rw-r--r-- | src/library/dao/settingsdao.cpp | 2 | ||||
-rw-r--r-- | src/library/dao/settingsdao.h | 2 | ||||
-rw-r--r-- | src/library/dao/trackdao.cpp | 2 | ||||
-rw-r--r-- | src/library/dao/trackdao.h | 11 | ||||
-rw-r--r-- | src/library/queryutil.h | 4 | ||||
-rw-r--r-- | src/library/schemamanager.cpp | 2 | ||||
-rw-r--r-- | src/library/schemamanager.h | 2 | ||||
-rw-r--r-- | src/library/trackcollection.cpp | 2 | ||||
-rw-r--r-- | src/library/trackcollection.h | 2 | ||||
-rw-r--r-- | src/util/db/dbconnection.cpp | 9 | ||||
-rw-r--r-- | src/util/db/dbconnection.h | 6 |
21 files changed, 31 insertions, 41 deletions
diff --git a/src/library/dao/analysisdao.cpp b/src/library/dao/analysisdao.cpp index da200545c0..6072ec0da5 100644 --- a/src/library/dao/analysisdao.cpp +++ b/src/library/dao/analysisdao.cpp @@ -17,7 +17,7 @@ const QString AnalysisDao::s_analysisTableName = "track_analysis"; // CPU time so I think we should stick with the default. rryan 4/3/2012 const int kCompressionLevel = -1; -AnalysisDao::AnalysisDao(QSqlDatabase& database, UserSettingsPointer pConfig) +AnalysisDao::AnalysisDao(const QSqlDatabase& database, UserSettingsPointer pConfig) : m_pConfig(pConfig), m_db(database) { QDir storagePath = getAnalysisStoragePath(); diff --git a/src/library/dao/analysisdao.h b/src/library/dao/analysisdao.h index 24e11e957c..0130a5a699 100644 --- a/src/library/dao/analysisdao.h +++ b/src/library/dao/analysisdao.h @@ -31,7 +31,7 @@ class AnalysisDao : public DAO { QByteArray data; }; - AnalysisDao(QSqlDatabase& database, UserSettingsPointer pConfig); + AnalysisDao(const QSqlDatabase& database, UserSettingsPointer pConfig); virtual ~AnalysisDao(); virtual void initialize(); diff --git a/src/library/dao/cuedao.cpp b/src/library/dao/cuedao.cpp index d45f28cd32..d3d4c74b00 100644 --- a/src/library/dao/cuedao.cpp +++ b/src/library/dao/cuedao.cpp @@ -12,7 +12,7 @@ #include "util/assert.h" #include "util/performancetimer.h" -CueDAO::CueDAO(QSqlDatabase& database) +CueDAO::CueDAO(const QSqlDatabase& database) : m_database(database) { } diff --git a/src/library/dao/cuedao.h b/src/library/dao/cuedao.h index e9326185e5..3642721b53 100644 --- a/src/library/dao/cuedao.h +++ b/src/library/dao/cuedao.h @@ -16,7 +16,7 @@ class Cue; class CueDAO : public DAO { public: - CueDAO(QSqlDatabase& database); + explicit CueDAO(const QSqlDatabase& database); virtual ~CueDAO(); void setDatabase(QSqlDatabase& database) { m_database = database; } @@ -34,7 +34,7 @@ class CueDAO : public DAO { private: CuePointer cueFromRow(const QSqlQuery& query) const; - QSqlDatabase& m_database; + QSqlDatabase m_database; mutable QMap<int, CuePointer> m_cues; }; diff --git a/src/library/dao/directorydao.cpp b/src/library/dao/directorydao.cpp index 11d5965247..a4f93fa5f4 100644 --- a/src/library/dao/directorydao.cpp +++ b/src/library/dao/directorydao.cpp @@ -11,7 +11,7 @@ #include "util/db/sqllikewildcardescaper.h" -DirectoryDAO::DirectoryDAO(QSqlDatabase& database) +DirectoryDAO::DirectoryDAO(const QSqlDatabase& database) : m_database(database) { } diff --git a/src/library/dao/directorydao.h b/src/library/dao/directorydao.h index fc9b49c325..7ee081dc06 100644 --- a/src/library/dao/directorydao.h +++ b/src/library/dao/directorydao.h @@ -16,7 +16,7 @@ enum ReturnCodes { class DirectoryDAO : public DAO { public: - DirectoryDAO(QSqlDatabase& database); + explicit DirectoryDAO(const QSqlDatabase& database); virtual ~DirectoryDAO(); void initialize(); @@ -28,7 +28,7 @@ class DirectoryDAO : public DAO { private: bool isChildDir(QString testDir, QString dirStr); - QSqlDatabase& m_database; + QSqlDatabase m_database; }; #endif //DIRECTORYDAO_H diff --git a/src/library/dao/libraryhashdao.cpp b/src/library/dao/libraryhashdao.cpp index 63ff28476d..bc35144313 100644 --- a/src/library/dao/libraryhashdao.cpp +++ b/src/library/dao/libraryhashdao.cpp @@ -8,7 +8,7 @@ #include "libraryhashdao.h" #include "library/queryutil.h" -LibraryHashDAO::LibraryHashDAO(QSqlDatabase& database) +LibraryHashDAO::LibraryHashDAO(const QSqlDatabase& database) : m_database(database) { } diff --git a/src/library/dao/libraryhashdao.h b/src/library/dao/libraryhashdao.h index 148ee22f4c..f108665054 100644 --- a/src/library/dao/libraryhashdao.h +++ b/src/library/dao/libraryhashdao.h @@ -10,7 +10,7 @@ class LibraryHashDAO : public DAO { public: - LibraryHashDAO(QSqlDatabase& database); + explicit LibraryHashDAO(const QSqlDatabase& database); virtual ~LibraryHashDAO(); void setDatabase(QSqlDatabase& database) { m_database = database; }; @@ -30,7 +30,7 @@ class LibraryHashDAO : public DAO { QStringList getDeletedDirectories(); private: - QSqlDatabase& m_database; + QSqlDatabase m_database; }; #endif //LIBRARYHASHDAO_H diff --git a/src/library/dao/playlistdao.cpp b/src/library/dao/playlistdao.cpp index 7a5476adb2..182c652e8e 100644 --- a/src/library/dao/playlistdao.cpp +++ b/src/library/dao/playlistdao.cpp @@ -8,7 +8,7 @@ #include "library/autodj/autodjprocessor.h" #include "util/math.h" -PlaylistDAO::PlaylistDAO(QSqlDatabase& database) +PlaylistDAO::PlaylistDAO(const QSqlDatabase& database) : m_database(database), m_pAutoDJProcessor(nullptr) { } diff --git a/src/library/dao/playlistdao.h b/src/library/dao/playlistdao.h index 578a0ebc78..c190d9ca62 100644 --- a/src/library/dao/playlistdao.h +++ b/src/library/dao/playlistdao.h @@ -46,7 +46,7 @@ class PlaylistDAO : public QObject, public virtual DAO { REPLACE, }; - PlaylistDAO(QSqlDatabase& database); + explicit PlaylistDAO(const QSqlDatabase& database); virtual ~PlaylistDAO(); void initialize(); @@ -140,7 +140,7 @@ class PlaylistDAO : public QObject, public virtual DAO { int* pTrackDistance); void populatePlaylistMembershipCache(); - QSqlDatabase& m_database; + QSqlDatabase m_database; QMultiHash<TrackId, int> m_playlistsTrackIsIn; AutoDJProcessor* m_pAutoDJProcessor; DISALLOW_COPY_AND_ASSIGN(PlaylistDAO); diff --git a/src/library/dao/settingsdao.cpp b/src/library/dao/settingsdao.cpp index 08c5496721..1c8cf4d47d 100644 --- a/src/library/dao/settingsdao.cpp +++ b/src/library/dao/settingsdao.cpp @@ -3,7 +3,7 @@ #include "library/dao/settingsdao.h" -SettingsDAO::SettingsDAO(QSqlDatabase& db) +SettingsDAO::SettingsDAO(const QSqlDatabase& db) : m_db(db) { } diff --git a/src/library/dao/settingsdao.h b/src/library/dao/settingsdao.h index 9cf5bad12b..8cd2882af0 100644 --- a/src/library/dao/settingsdao.h +++ b/src/library/dao/settingsdao.h @@ -14,7 +14,7 @@ // All library-specific preferences go in the library settings table class SettingsDAO : public QObject { public: - SettingsDAO(QSqlDatabase &db); + SettingsDAO(const QSqlDatabase& db); virtual ~SettingsDAO(); virtual void initialize(); diff --git a/src/library/dao/trackdao.cpp b/src/library/dao/trackdao.cpp index 5bc3473c7b..18d4d38ef8 100644 --- a/src/library/dao/trackdao.cpp +++ b/src/library/dao/trackdao.cpp @@ -68,7 +68,7 @@ RecentTrackCacheItem::~RecentTrackCacheItem() { // expensive. const int kRecentTracksCacheSize = 5; -TrackDAO::TrackDAO(QSqlDatabase& database, +TrackDAO::TrackDAO(const QSqlDatabase& database, CueDAO& cueDao, PlaylistDAO& playlistDao, AnalysisDao& analysisDao, diff --git a/src/library/dao/trackdao.h b/src/library/dao/trackdao.h index 7fb097ff95..807ed35c4d 100644 --- a/src/library/dao/trackdao.h +++ b/src/library/dao/trackdao.h @@ -54,11 +54,12 @@ class TrackDAO : public QObject, public virtual DAO { public: // The 'config object' is necessary because users decide ID3 tags get // synchronized on track metadata change - TrackDAO(QSqlDatabase& database, CueDAO& cueDao, - PlaylistDAO& playlistDao, - AnalysisDao& analysisDao, - LibraryHashDAO& libraryHashDao, - UserSettingsPointer pConfig); + TrackDAO(const QSqlDatabase& database, + CueDAO& cueDao, + PlaylistDAO& playlistDao, + AnalysisDao& analysisDao, + LibraryHashDAO& libraryHashDao, + UserSettingsPointer pConfig); virtual ~TrackDAO(); void finish(); diff --git a/src/library/queryutil.h b/src/library/queryutil.h index a0742ac83b..bcc10b8b98 100644 --- a/src/library/queryutil.h +++ b/src/library/queryutil.h @@ -10,7 +10,7 @@ class ScopedTransaction { public: - explicit ScopedTransaction(QSqlDatabase& database) : + explicit ScopedTransaction(const QSqlDatabase& database) : m_database(database), m_active(false) { if (!transaction()) { @@ -62,7 +62,7 @@ class ScopedTransaction { return result; } private: - QSqlDatabase& m_database; + QSqlDatabase m_database; bool m_active; }; diff --git a/src/library/schemamanager.cpp b/src/library/schemamanager.cpp index 057bfe3be1..685953e943 100644 --- a/src/library/schemamanager.cpp +++ b/src/library/schemamanager.cpp @@ -14,7 +14,7 @@ const QString SchemaManager::SETTINGS_MINCOMPATIBLE_STRING = "mixxx.schema.min_c // static SchemaManager::Result SchemaManager::upgradeToSchemaVersion( const QString& schemaFilename, - QSqlDatabase& db, const int targetVersion) { + const QSqlDatabase& db, const int targetVersion) { SettingsDAO settings(db); int currentVersion = getCurrentSchemaVersion(settings); VERIFY_OR_DEBUG_ASSERT(currentVersion >= 0) { diff --git a/src/library/schemamanager.h b/src/library/schemamanager.h index 3997a6c95b..a79bc8620c 100644 --- a/src/library/schemamanager.h +++ b/src/library/schemamanager.h @@ -19,7 +19,7 @@ class SchemaManager { }; static Result upgradeToSchemaVersion(const QString& schemaFilename, - QSqlDatabase& db, const int targetVersion); + const QSqlDatabase& db, const int targetVersion); static const QString SETTINGS_VERSION_STRING; static const QString SETTINGS_MINCOMPATIBLE_STRING; diff --git a/src/library/trackcollection.cpp b/src/library/trackcollection.cpp index 0a5fd9f232..f54ec4b688 100644 --- a/src/library/trackcollection.cpp +++ b/src/library/trackcollection.cpp @@ -38,7 +38,7 @@ TrackCollection::~TrackCollection() { } bool TrackCollection::checkForTables() { - if (!m_dbConnection) { + if (!m_dbConnection.database().isOpen()) { QMessageBox::critical(0, tr("Cannot open database"), tr("Unable to establish a database connection.\n" "Mixxx requires QT with SQLite support. Please read " diff --git a/src/library/trackcollection.h b/src/library/trackcollection.h index 903421dcf5..209f38e003 100644 --- a/src/library/trackcollection.h +++ b/src/library/trackcollection.h @@ -38,7 +38,7 @@ class TrackCollection : public QObject { void resetLibaryCancellation(); - QSqlDatabase& database() { + QSqlDatabase database() { return m_dbConnection.database(); } diff --git a/src/util/db/dbconnection.cpp b/src/util/db/dbconnection.cpp index 295c10d8f0..60fb3c0a3a 100644 --- a/src/util/db/dbconnection.cpp +++ b/src/util/db/dbconnection.cpp @@ -201,7 +201,6 @@ DbConnection::DbConnection(const QString& dirPath) qWarning() << "Failed to open database connection:" << *this << m_database.lastError(); - DEBUG_ASSERT(!*this); // failure return; // early exit } @@ -216,7 +215,6 @@ DbConnection::DbConnection(const QString& dirPath) VERIFY_OR_DEBUG_ASSERT(handle != nullptr) { qWarning() << "Could not get sqlite3 handle"; m_database.close(); - DEBUG_ASSERT(!*this); // failure return; // early exit } @@ -253,9 +251,6 @@ DbConnection::DbConnection(const QString& dirPath) VERIFY_OR_DEBUG_ASSERT(result == SQLITE_OK) { qWarning() << "Failed to install like 3 function:" << result; } - - DEBUG_ASSERT(*this); // success - return; // early exit } else { qWarning() << "localecompare requires a SQLite3 database driver, found:" << v.typeName(); @@ -264,7 +259,7 @@ DbConnection::DbConnection(const QString& dirPath) } DbConnection::~DbConnection() { - VERIFY_OR_DEBUG_ASSERT(*this) { + VERIFY_OR_DEBUG_ASSERT(m_database.isOpen()) { qWarning() << "Database connection has already been closed:" << *this; @@ -278,12 +273,10 @@ DbConnection::~DbConnection() { << "Rolled back open transaction before closing database connection:" << *this; } - DEBUG_ASSERT(*this); qDebug() << "Closing database connection:" << *this; m_database.close(); - DEBUG_ASSERT(!*this); } QDebug operator<<(QDebug debug, const DbConnection& dbConnection) { diff --git a/src/util/db/dbconnection.h b/src/util/db/dbconnection.h index ee320a460a..8820bb7fa1 100644 --- a/src/util/db/dbconnection.h +++ b/src/util/db/dbconnection.h @@ -12,11 +12,7 @@ class DbConnection final { const QString& dirPath); ~DbConnection(); - operator bool() const { - return m_database.isOpen(); - } - - QSqlDatabase& database() { + QSqlDatabase database() const { return m_database; } |