don't touch the db if qapp is closing down
This commit is contained in:
parent
858a19991e
commit
32e3e6cf9c
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
#include "storagethread_p.h"
|
#include "storagethread_p.h"
|
||||||
|
|
||||||
|
#include <QCoreApplication>
|
||||||
#include <QSqlError>
|
#include <QSqlError>
|
||||||
#include <QSqlQuery>
|
#include <QSqlQuery>
|
||||||
#include <QSqlField>
|
#include <QSqlField>
|
||||||
@ -47,13 +48,14 @@ K_GLOBAL_STATIC(StorageThreadSingleton, privateStorageThreadSelf)
|
|||||||
StorageThread::StorageThread(QObject *parent)
|
StorageThread::StorageThread(QObject *parent)
|
||||||
: QThread(parent)
|
: QThread(parent)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
StorageThread::~StorageThread()
|
StorageThread::~StorageThread()
|
||||||
{
|
{
|
||||||
|
if (QCoreApplication::closingDown()) {
|
||||||
QString name = m_db.connectionName();
|
QString name = m_db.connectionName();
|
||||||
QSqlDatabase::removeDatabase(name);
|
QSqlDatabase::removeDatabase(name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Plasma::StorageThread *StorageThread::self()
|
Plasma::StorageThread *StorageThread::self()
|
||||||
@ -139,6 +141,7 @@ void StorageThread::save(QWeakPointer<StorageJob> wcaller, const QVariantMap &pa
|
|||||||
query.bindValue(":id", it.key());
|
query.bindValue(":id", it.key());
|
||||||
|
|
||||||
QString field;
|
QString field;
|
||||||
|
bool binary = false;
|
||||||
switch (QMetaType::Type(it.value().type())) {
|
switch (QMetaType::Type(it.value().type())) {
|
||||||
case QVariant::String:
|
case QVariant::String:
|
||||||
field = ":txt";
|
field = ":txt";
|
||||||
@ -151,6 +154,7 @@ void StorageThread::save(QWeakPointer<StorageJob> wcaller, const QVariantMap &pa
|
|||||||
field = ":float";
|
field = ":float";
|
||||||
break;
|
break;
|
||||||
case QVariant::ByteArray:
|
case QVariant::ByteArray:
|
||||||
|
binary = true;
|
||||||
field = ":binary";
|
field = ":binary";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -158,7 +162,14 @@ void StorageThread::save(QWeakPointer<StorageJob> wcaller, const QVariantMap &pa
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (binary) {
|
||||||
|
QByteArray b;
|
||||||
|
QDataStream ds(&b, QIODevice::WriteOnly);
|
||||||
|
ds << it.value();
|
||||||
|
query.bindValue(field, ds);
|
||||||
|
} else {
|
||||||
query.bindValue(field, it.value());
|
query.bindValue(field, it.value());
|
||||||
|
}
|
||||||
|
|
||||||
if (!query.exec()) {
|
if (!query.exec()) {
|
||||||
//kDebug() << "query failed:" << query.lastQuery() << query.lastError().text();
|
//kDebug() << "query failed:" << query.lastQuery() << query.lastError().text();
|
||||||
@ -233,7 +244,10 @@ void StorageThread::retrieve(QWeakPointer<StorageJob> wcaller, const QVariantMap
|
|||||||
} else if (!query.value(floatColumn).isNull()) {
|
} else if (!query.value(floatColumn).isNull()) {
|
||||||
data.insert(key, query.value(floatColumn));
|
data.insert(key, query.value(floatColumn));
|
||||||
} else if (!query.value(binaryColumn).isNull()) {
|
} 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user