From 32e3e6cf9c7f1fb7c1d5252854728bc4ea64bf17 Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Fri, 29 Apr 2011 01:03:17 +0200 Subject: [PATCH] don't touch the db if qapp is closing down --- private/storagethread.cpp | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/private/storagethread.cpp b/private/storagethread.cpp index b7210d2df..3c2667bca 100644 --- a/private/storagethread.cpp +++ b/private/storagethread.cpp @@ -19,6 +19,7 @@ #include "storagethread_p.h" +#include #include #include #include @@ -47,13 +48,14 @@ K_GLOBAL_STATIC(StorageThreadSingleton, privateStorageThreadSelf) StorageThread::StorageThread(QObject *parent) : QThread(parent) { - } StorageThread::~StorageThread() { - QString name = m_db.connectionName(); - QSqlDatabase::removeDatabase(name); + if (QCoreApplication::closingDown()) { + QString name = m_db.connectionName(); + QSqlDatabase::removeDatabase(name); + } } Plasma::StorageThread *StorageThread::self() @@ -139,6 +141,7 @@ void StorageThread::save(QWeakPointer wcaller, const QVariantMap &pa query.bindValue(":id", it.key()); QString field; + bool binary = false; switch (QMetaType::Type(it.value().type())) { case QVariant::String: field = ":txt"; @@ -151,6 +154,7 @@ void StorageThread::save(QWeakPointer wcaller, const QVariantMap &pa field = ":float"; break; case QVariant::ByteArray: + binary = true; field = ":binary"; break; default: @@ -158,7 +162,14 @@ void StorageThread::save(QWeakPointer wcaller, const QVariantMap &pa break; } - query.bindValue(field, it.value()); + if (binary) { + QByteArray b; + QDataStream ds(&b, QIODevice::WriteOnly); + ds << it.value(); + query.bindValue(field, ds); + } else { + query.bindValue(field, it.value()); + } if (!query.exec()) { //kDebug() << "query failed:" << query.lastQuery() << query.lastError().text(); @@ -233,7 +244,10 @@ void StorageThread::retrieve(QWeakPointer wcaller, const QVariantMap } else if (!query.value(floatColumn).isNull()) { data.insert(key, query.value(floatColumn)); } else if (!query.value(binaryColumn).isNull()) { - data.insert(key, query.value(binaryColumn)); + QByteArray bytes = query.value(binaryColumn).toByteArray(); + QDataStream in(bytes); + QVariant v(in); + data.insert(key, v); } }