Mercurial > dedupe
comparison SqliteDBLink.cpp @ 87:9e337bd96bd3
Improve efficiency of SqliteDBLink::filesWithSize
| author | Tom Fredrik Blenning Klaussen <bfg@bfgconsult.no> |
|---|---|
| date | Thu, 10 Oct 2013 16:12:41 +0200 |
| parents | af7962f3274b |
| children | 6e1d4d2fc49b |
comparison
equal
deleted
inserted
replaced
| 86:af7962f3274b | 87:9e337bd96bd3 |
|---|---|
| 199 } | 199 } |
| 200 | 200 |
| 201 const QList<FileDBLink::dbinf_ptr_t> | 201 const QList<FileDBLink::dbinf_ptr_t> |
| 202 SqliteDBLink::filesWithSize(quint64 size, const QString& prefix) const | 202 SqliteDBLink::filesWithSize(quint64 size, const QString& prefix) const |
| 203 { | 203 { |
| 204 //This is incredibly inefficient and should be reimplemented | 204 QList<FileDBLink::dbinf_ptr_t > values; |
| 205 return FileDBLink::filesWithSize(size, prefix); | 205 |
| 206 } | 206 QSqlQuery query(db); |
| 207 | |
| 208 if (prefix.size() > 0) { | |
| 209 query.prepare("SELECT * FROM files WHERE path LIKE :prefix AND size = :size"); | |
| 210 query.bindValue(":prefix", QString("%1%").arg(prefix)); | |
| 211 } | |
| 212 else { | |
| 213 query.prepare("SELECT * FROM files WHERE size = :size"); | |
| 214 } | |
| 215 query.bindValue(":size", QString("%1%").arg(size)); | |
| 216 | |
| 217 | |
| 218 if (!query.exec()) { | |
| 219 throw SQLException(query); | |
| 220 } | |
| 221 | |
| 222 int pathIndex = query.record().indexOf("path"); | |
| 223 int sizeIndex = query.record().indexOf("size"); | |
| 224 int dateIndex = query.record().indexOf("mtime"); | |
| 225 int checksumIndex = query.record().indexOf("checksum"); | |
| 226 while (query.next()) { | |
| 227 QString path = query.value(pathIndex).toString(); | |
| 228 quint64 size = query.value(sizeIndex).toInt(); | |
| 229 QDateTime mtime = query.value(dateIndex).toDateTime(); | |
| 230 QByteArray checksum = query.value(checksumIndex).toByteArray(); | |
| 231 | |
| 232 values << | |
| 233 FileDBLink::dbinf_ptr_t(new FileDBLink::DBInfo(path, | |
| 234 size, mtime, checksum)); | |
| 235 } | |
| 236 | |
| 237 return values; | |
| 238 } |
