Mercurial > dedupe
changeset 96:c7da835ea912
Support for prefix in commit.
| author | Tom Fredrik Blenning Klaussen <bfg@bfgconsult.no> |
|---|---|
| date | Tue, 22 Oct 2013 14:40:08 +0200 |
| parents | 7c935d3d5b74 |
| children | 34f11b2a1178 |
| files | DataController.cpp FileDBLink.cpp FileDBLink.hpp SqliteDBLink.cpp SqliteDBLink.hpp |
| diffstat | 5 files changed, 17 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/DataController.cpp Tue Oct 22 14:22:00 2013 +0200 +++ b/DataController.cpp Tue Oct 22 14:40:08 2013 +0200 @@ -126,7 +126,7 @@ last = now; } } - dblink.commit(); + dblink.commit(dir.path()); }
--- a/FileDBLink.cpp Tue Oct 22 14:22:00 2013 +0200 +++ b/FileDBLink.cpp Tue Oct 22 14:40:08 2013 +0200 @@ -225,7 +225,7 @@ return dbinf_ptr_t(); } -bool FileDBLink::commit() +bool FileDBLink::commit(const QString&) { return true; }
--- a/FileDBLink.hpp Tue Oct 22 14:22:00 2013 +0200 +++ b/FileDBLink.hpp Tue Oct 22 14:40:08 2013 +0200 @@ -145,7 +145,7 @@ virtual DBStatus existsWithMtime(const QString& path, const QDateTime& mtime) = 0; - virtual bool commit(); + virtual bool commit(const QString& prefix = QString()); virtual const QList<dbinf_ptr_t> values(const QString& prefix = QString() ) const = 0;
--- a/SqliteDBLink.cpp Tue Oct 22 14:22:00 2013 +0200 +++ b/SqliteDBLink.cpp Tue Oct 22 14:40:08 2013 +0200 @@ -294,7 +294,7 @@ checksums.clear(); } -bool SqliteDBLink::commit() +bool SqliteDBLink::commit(const QString& prefix) { OperationType last = None; QVariantList paths, sizes, mtimes, hashes; @@ -321,8 +321,18 @@ } QSqlQuery whatToUpdate(db); - whatToUpdate.prepare("SELECT path FROM files WHERE checksum is NULL AND size in (SELECT size FROM files WHERE size <> 0 GROUP BY size HAVING count(*) > 1 ORDER BY SIZE) ORDER BY size"); - + QString whatToUpdateQuery = "SELECT path FROM files WHERE checksum is NULL AND size in (SELECT size FROM files WHERE size <> 0 GROUP BY size HAVING count(*) > 1 ORDER BY SIZE) %1 ORDER BY size"; + if (prefix.isEmpty()) { + whatToUpdateQuery = whatToUpdateQuery.arg(""); + } + else { + whatToUpdateQuery = whatToUpdateQuery.arg("AND path LIKE :prefix"); + } + whatToUpdate.prepare(whatToUpdateQuery); + if (!prefix.isEmpty()) { + whatToUpdate.bindValue("prefix", QString("%1%").arg(prefix)); + } + if (!whatToUpdate.exec()) { throw SQLException(whatToUpdate); }
--- a/SqliteDBLink.hpp Tue Oct 22 14:22:00 2013 +0200 +++ b/SqliteDBLink.hpp Tue Oct 22 14:40:08 2013 +0200 @@ -28,7 +28,7 @@ virtual void keepOnlyFromPrefix(const QString& prefix, const QStringList& files); virtual void deleteFileFromDB(const QString& path); - bool commit(); + bool commit(const QString& prefix = QString() ); private: typedef enum {None = 0, Add, Update } OperationType;
