Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[qtcontacts-sqlite] Serialize QContactExtendedDetail data. JB#51541
Store QContactExtendedDetail::data() as serialized bytes, otherwise
the data is not set and retrieved as expected.
  • Loading branch information
blammit committed Oct 19, 2020
1 parent 6e7e4da commit a1ca27e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/engine/contactreader.cpp
Expand Up @@ -81,6 +81,8 @@

#include <QSqlError>
#include <QVector>
#include <QBuffer>
#include <QDataStream>

#include <QtDebug>
#include <QElapsedTimer>
Expand Down Expand Up @@ -624,7 +626,15 @@ static const FieldInfo extendedDetailFields[] =
static void setValues(QContactExtendedDetail *detail, QSqlQuery *query, const int offset)
{
setValue(detail, QContactExtendedDetail::FieldName, query->value(offset + 0));
setValue(detail, QContactExtendedDetail::FieldData, query->value(offset + 1));

QByteArray bytes = query->value(offset + 1).toByteArray();
QBuffer buffer(&bytes);
buffer.open(QIODevice::ReadOnly);
QDataStream in(&buffer);
in.setVersion(QDataStream::Qt_5_6);
QVariant deserialized;
in >> deserialized;
setValue(detail, QContactExtendedDetail::FieldData, deserialized);
}

static QMap<QString, int> contextTypes()
Expand Down
12 changes: 11 additions & 1 deletion src/engine/contactwriter.cpp
Expand Up @@ -55,6 +55,8 @@

#include <QSqlError>
#include <QUuid>
#include <QBuffer>
#include <QDataStream>

#include <algorithm>
#include <cmath>
Expand Down Expand Up @@ -3218,7 +3220,15 @@ ContactsDatabase::Query bindDetail(ContactsDatabase &db, quint32 contactId, quin
query.bindValue(":detailId", detailId);
query.bindValue(":contactId", contactId);
query.bindValue(":name", detailValue(detail, T::FieldName));
query.bindValue(":data", detailValue(detail, T::FieldData));

QByteArray serialized;
QBuffer buffer(&serialized);
buffer.open(QIODevice::WriteOnly);
QDataStream out(&buffer);
out.setVersion(QDataStream::Qt_5_6);
out << detailValue(detail, T::FieldData);
query.bindValue(":data", serialized);

return query;
}

Expand Down

0 comments on commit a1ca27e

Please sign in to comment.