diff options
author | RJ Ryan <rryan@mixxx.org> | 2014-11-13 15:30:54 -0500 |
---|---|---|
committer | RJ Ryan <rryan@mixxx.org> | 2014-11-13 15:33:16 -0500 |
commit | 202c858d4eaee149885c66fd41fedb873a1e6564 (patch) | |
tree | f260bec46a448f487e59c336baf150bb68026d65 /src/library | |
parent | 058328f439d02c3d5a60c87d98e1f7c4056b4546 (diff) |
Don't double-escape verified directory list (at the expense of escaping twice).
Diffstat (limited to 'src/library')
-rw-r--r-- | src/library/dao/libraryhashdao.cpp | 6 | ||||
-rw-r--r-- | src/library/dao/libraryhashdao.h | 6 | ||||
-rw-r--r-- | src/library/dao/trackdao.cpp | 10 | ||||
-rw-r--r-- | src/library/dao/trackdao.h | 2 | ||||
-rw-r--r-- | src/library/queryutil.h | 13 |
5 files changed, 22 insertions, 15 deletions
diff --git a/src/library/dao/libraryhashdao.cpp b/src/library/dao/libraryhashdao.cpp index f27347a48a..63ff28476d 100644 --- a/src/library/dao/libraryhashdao.cpp +++ b/src/library/dao/libraryhashdao.cpp @@ -107,11 +107,7 @@ void LibraryHashDAO::updateDirectoryStatuses(const QStringList& dirPaths, const bool verified) { //qDebug() << "LibraryHashDAO::updateDirectoryStatus" << QThread::currentThread() << m_database.connectionName(); FieldEscaper escaper(m_database); - QStringList escapedDirPaths = dirPaths; - QMutableStringListIterator it(escapedDirPaths); - while (it.hasNext()) { - it.setValue(escaper.escapeString(it.next())); - } + QStringList escapedDirPaths = escaper.escapeStrings(dirPaths); QSqlQuery query(m_database); query.prepare( diff --git a/src/library/dao/libraryhashdao.h b/src/library/dao/libraryhashdao.h index 96e213c4f8..148ee22f4c 100644 --- a/src/library/dao/libraryhashdao.h +++ b/src/library/dao/libraryhashdao.h @@ -19,12 +19,14 @@ class LibraryHashDAO : public DAO { QHash<QString, int> getDirectoryHashes(); int getDirectoryHash(const QString& dirPath); void saveDirectoryHash(const QString& dirPath, const int hash); - void updateDirectoryHash(const QString& dirPath, const int newHash, const int dir_deleted); + void updateDirectoryHash(const QString& dirPath, const int newHash, + const int dir_deleted); void markAsExisting(const QString& dirPath); void invalidateAllDirectories(); void markUnverifiedDirectoriesAsDeleted(); void removeDeletedDirectoryHashes(); - void updateDirectoryStatuses(const QStringList& dirPaths, const bool deleted, const bool verified); + void updateDirectoryStatuses(const QStringList& dirPaths, + const bool deleted, const bool verified); QStringList getDeletedDirectories(); private: diff --git a/src/library/dao/trackdao.cpp b/src/library/dao/trackdao.cpp index 0e5c9f7c9d..a17b2a3931 100644 --- a/src/library/dao/trackdao.cpp +++ b/src/library/dao/trackdao.cpp @@ -1292,21 +1292,17 @@ void TrackDAO::markTrackLocationAsVerified(const QString& location) { } } -void TrackDAO::markTracksInDirectoriesAsVerified(QStringList& directories) { +void TrackDAO::markTracksInDirectoriesAsVerified(const QStringList& directories) { //qDebug() << "TrackDAO::markTracksInDirectoryAsVerified" << QThread::currentThread() << m_database.connectionName(); - //qDebug() << "markTracksInDirectoryAsVerified()" << directory; FieldEscaper escaper(m_database); - QMutableStringListIterator it(directories); - while (it.hasNext()) { - it.setValue(escaper.escapeString(it.next())); - } + QStringList escapedDirectories = escaper.escapeStrings(directories); QSqlQuery query(m_database); query.prepare( QString("UPDATE track_locations " "SET needs_verification=0 " - "WHERE directory IN (%1)").arg(directories.join(","))); + "WHERE directory IN (%1)").arg(escapedDirectories.join(","))); if (!query.exec()) { LOG_FAILED_QUERY(query) << "Couldn't mark tracks in" << directories.size() << "directories as verified."; diff --git a/src/library/dao/trackdao.h b/src/library/dao/trackdao.h index 0464e7abbf..88a1f957c2 100644 --- a/src/library/dao/trackdao.h +++ b/src/library/dao/trackdao.h @@ -109,7 +109,7 @@ class TrackDAO : public QObject, public virtual DAO { // Scanning related calls. Should be elsewhere or private somehow. void markTrackLocationAsVerified(const QString& location); - void markTracksInDirectoriesAsVerified(QStringList& directories); + void markTracksInDirectoriesAsVerified(const QStringList& directories); void invalidateTrackLocationsInLibrary(); void markUnverifiedTracksAsDeleted(); void markTrackLocationsAsDeleted(const QString& directory); diff --git a/src/library/queryutil.h b/src/library/queryutil.h index 337232adeb..878772fb5e 100644 --- a/src/library/queryutil.h +++ b/src/library/queryutil.h @@ -81,6 +81,19 @@ class FieldEscaper { return m_database.driver()->formatValue(m_stringField); } + QStringList escapeStrings(const QStringList& escapeStrings) const { + QStringList result = escapeStrings; + escapeStringsInPlace(&result); + return result; + } + + void escapeStringsInPlace(QStringList* pEscapeStrings) const { + QMutableStringListIterator it(*pEscapeStrings); + while (it.hasNext()) { + it.setValue(escapeString(it.next())); + } + } + // Escapes a string for use in a LIKE operation by prefixing instances of // LIKE wildcard characters (% and _) with escapeCharacter. This allows the // caller to then attach wildcard characters to the string. This does NOT |