Mercurial > dedupe
diff SqliteDBLink.cpp @ 16:06166d6c083b
Add configuration processing.
Cache DB values
Add a custom RBTree to save space.
Track multiple DB connections properly.
More testing.
Add ValueExistsException.
| author | Tom Fredrik Blenning Klaussen <bfg@blenning.no> |
|---|---|
| date | Tue, 28 Aug 2012 18:58:02 +0200 |
| parents | b5943e4bf676 |
| children | bf3dce7fedcb |
line wrap: on
line diff
--- a/SqliteDBLink.cpp Sat Aug 25 01:42:13 2012 +0200 +++ b/SqliteDBLink.cpp Tue Aug 28 18:58:02 2012 +0200 @@ -11,11 +11,11 @@ SqliteDBLink::SqliteDBLink(const QString& dbPath) { - db = QSqlDatabase::addDatabase("QSQLITE"); + db = QSqlDatabase::addDatabase("QSQLITE", "SqliteDBLink"); db.setDatabaseName(dbPath); bool ok = db.open(); assert(ok); - QSqlQuery query; + QSqlQuery query(db); if (!query.exec(QString("SELECT * FROM files;"))) { query.exec("CREATE TABLE files(path VARCHAR PRIMARY KEY ASC, size INTEGER, mtime TEXT, checksum TEXT);"); } @@ -33,7 +33,7 @@ bool SqliteDBLink::exists(const QString& path) { - QSqlQuery query; + QSqlQuery query(db); query.prepare("SELECT path FROM files WHERE path = :path;"); query.bindValue(":path", path); if (!query.exec()) { @@ -44,7 +44,7 @@ FileDBLink::DBStatus SqliteDBLink::existsWithMtime(const QString& path, const QDateTime& mtime) { - QSqlQuery query; + QSqlQuery query(db); query.prepare("SELECT mtime FROM files WHERE path = :path;"); query.bindValue(":path", path); if (!query.exec()) { @@ -69,7 +69,7 @@ { if (exists(dbinfo.path())) return false; - QSqlQuery query; + QSqlQuery query(db); query.prepare("INSERT INTO files (path, size, mtime, checksum) " "VALUES (:path, :size, :mtime, :checksum)"); query.bindValue(":path", dbinfo.path()); @@ -89,7 +89,7 @@ void SqliteDBLink::updateFile(const DBInfo& dbinfo) { - QSqlQuery query; + QSqlQuery query(db); query.prepare("UPDATE files SET size=:size, mtime=:mtime, checksum=:checksum WHERE path=:path"); query.bindValue(":path", dbinfo.path()); query.bindValue(":size", dbinfo.size()); @@ -124,7 +124,7 @@ { QList<QSharedPointer<FileDBLink::DBInfo> > values; - QSqlQuery query; + QSqlQuery query(db); if (prefix.size() > 0) { query.prepare("SELECT * FROM files WHERE path LIKE :prefix"); @@ -158,12 +158,12 @@ void SqliteDBLink::deleteFileFromDB(const QString& path) { - QSqlQuery query; - query.prepare("DELETE FROM files WHERE path = :path"); - query.bindValue(":path", path); - if (!query.exec()) { - qDebug() << path << "::" << query.lastQuery() << "::" << query.lastError().text(); - } + QSqlQuery query(db); + query.prepare("DELETE FROM files WHERE path = :path"); + query.bindValue(":path", path); + if (!query.exec()) { + qDebug() << path << "::" << query.lastQuery() << "::" << query.lastError().text(); + } }
