mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 18:56:34 +01:00
IconProvider: Use SqlQueryJob to save icons to database
Also use INSERT OR REPLACE instead of two separate queries.
This commit is contained in:
parent
e61352c70c
commit
977bce9886
@ -244,25 +244,14 @@ IconProvider* IconProvider::instance()
|
|||||||
void IconProvider::saveIconsToDatabase()
|
void IconProvider::saveIconsToDatabase()
|
||||||
{
|
{
|
||||||
foreach (const BufferedIcon &ic, m_iconBuffer) {
|
foreach (const BufferedIcon &ic, m_iconBuffer) {
|
||||||
QSqlQuery query(SqlDatabase::instance()->database());
|
|
||||||
query.prepare("SELECT id FROM icons WHERE url = ?");
|
|
||||||
query.bindValue(0, encodeUrl(ic.first));
|
|
||||||
query.exec();
|
|
||||||
|
|
||||||
if (query.next()) {
|
|
||||||
query.prepare("UPDATE icons SET icon = ? WHERE url = ?");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
query.prepare("INSERT INTO icons (icon, url) VALUES (?,?)");
|
|
||||||
}
|
|
||||||
|
|
||||||
QByteArray ba;
|
QByteArray ba;
|
||||||
QBuffer buffer(&ba);
|
QBuffer buffer(&ba);
|
||||||
buffer.open(QIODevice::WriteOnly);
|
buffer.open(QIODevice::WriteOnly);
|
||||||
ic.second.save(&buffer, "PNG");
|
ic.second.save(&buffer, "PNG");
|
||||||
query.bindValue(0, buffer.data());
|
auto job = new SqlQueryJob(QSL("INSERT OR REPLACE INTO icons (icon, url) VALUES (?,?)"), this);
|
||||||
query.bindValue(1, QString::fromUtf8(encodeUrl(ic.first)));
|
job->addBindValue(buffer.data());
|
||||||
query.exec();
|
job->addBindValue(QString::fromUtf8(encodeUrl(ic.first)));
|
||||||
|
job->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_iconBuffer.clear();
|
m_iconBuffer.clear();
|
||||||
|
Loading…
Reference in New Issue
Block a user