Changeset View
Changeset View
Standalone View
Standalone View
runners/bookmarks/fetchsqlite.cpp
Show All 24 Lines | |||||
25 | #include "bookmarksrunner_defs.h" | 25 | #include "bookmarksrunner_defs.h" | ||
26 | #include <QSqlQuery> | 26 | #include <QSqlQuery> | ||
27 | #include <QSqlError> | 27 | #include <QSqlError> | ||
28 | #include <QSqlRecord> | 28 | #include <QSqlRecord> | ||
29 | #include <QMutexLocker> | 29 | #include <QMutexLocker> | ||
30 | #include <thread> | 30 | #include <thread> | ||
31 | #include <sstream> | 31 | #include <sstream> | ||
32 | 32 | | |||
33 | FetchSqlite::FetchSqlite(const QString &originalFilePath, const QString ©To, QObject *parent) : | 33 | FetchSqlite::FetchSqlite(const QString &databaseFile, QObject *parent) : | ||
34 | QObject(parent), m_databaseFile(copyTo) | 34 | QObject(parent), m_databaseFile(databaseFile) | ||
35 | { | 35 | { | ||
36 | QFile originalFile(originalFilePath); | | |||
37 | QFile(copyTo).remove(); | | |||
38 | bool couldCopy = originalFile.copy(copyTo); | | |||
39 | if(!couldCopy) { | | |||
40 | //qDebug() << "error copying favicon database from " << originalFile.fileName() << " to " << copyTo; | | |||
41 | //qDebug() << originalFile.errorString(); | | |||
42 | } | | |||
43 | } | 36 | } | ||
44 | 37 | | |||
45 | FetchSqlite::~FetchSqlite() | 38 | FetchSqlite::~FetchSqlite() | ||
46 | { | 39 | { | ||
47 | QFile(m_databaseFile).remove(); | | |||
48 | } | 40 | } | ||
49 | 41 | | |||
50 | void FetchSqlite::prepare() | 42 | void FetchSqlite::prepare() | ||
meven: Can be removed as well | |||||
alex: I would rather do that in another patch. | |||||
51 | { | 43 | { | ||
52 | } | 44 | } | ||
53 | 45 | | |||
54 | void FetchSqlite::teardown() | 46 | void FetchSqlite::teardown() | ||
55 | { | 47 | { | ||
56 | QString connectionPrefix = m_databaseFile + "-"; | 48 | QString connectionPrefix = m_databaseFile + "-"; | ||
57 | 49 | | |||
58 | const auto connections = QSqlDatabase::connectionNames(); | 50 | const auto connections = QSqlDatabase::connectionNames(); | ||
Show All 28 Lines | 59 | static QSqlDatabase openDbConnection(const QString& databaseFile) { | |||
87 | 79 | | |||
88 | return db; | 80 | return db; | ||
89 | } | 81 | } | ||
90 | 82 | | |||
91 | QList<QVariantMap> FetchSqlite::query(const QString &sql, QMap<QString, QVariant> bindObjects) | 83 | QList<QVariantMap> FetchSqlite::query(const QString &sql, QMap<QString, QVariant> bindObjects) | ||
92 | { | 84 | { | ||
93 | QMutexLocker lock(&m_mutex); | 85 | QMutexLocker lock(&m_mutex); | ||
94 | 86 | | |||
95 | auto db = openDbConnection(m_databaseFile); | 87 | auto db = openDbConnection(m_databaseFile); | ||
88 | if (!db.isValid()) { | ||||
89 | return QList<QVariantMap>(); | ||||
90 | } | ||||
We might want to reuse database connection as long as the databaseFile did not change meven: We might want to reuse database connection as long as the databaseFile did not change | |||||
alex: I will do that in a follow up patch :-) | |||||
96 | 91 | | |||
97 | //qDebug() << "query: " << sql; | 92 | //qDebug() << "query: " << sql; | ||
98 | QSqlQuery query(db); | 93 | QSqlQuery query(db); | ||
99 | query.prepare(sql); | 94 | query.prepare(sql); | ||
100 | for (auto entry = bindObjects.constKeyValueBegin(); entry != bindObjects.constKeyValueEnd(); ++entry) { | 95 | for (auto entry = bindObjects.constKeyValueBegin(); entry != bindObjects.constKeyValueEnd(); ++entry) { | ||
101 | query.bindValue((*entry).first, (*entry).second); | 96 | query.bindValue((*entry).first, (*entry).second); | ||
102 | //qDebug() << "* Bound " << variableName << " to " << query.boundValue(variableName); | 97 | //qDebug() << "* Bound " << variableName << " to " << query.boundValue(variableName); | ||
103 | } | 98 | } | ||
Show All 28 Lines |
Can be removed as well