Skip to content

Commit

Permalink
Ensure we don't serialise null QContactExtendedDetail data
Browse files Browse the repository at this point in the history
Previous changes related to JB#51541 and JB#51806 broke one of the
tst_qcontactmanager unit tests.  This commit ensures that we don't
attempt to serialise a null QVariant as a QByteArray, but instead
write it directly, so that the round trip is stable.
  • Loading branch information
chriadam committed Dec 2, 2020
1 parent 7c3a7d3 commit 8fc7741
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/engine/contactwriter.cpp
Expand Up @@ -3235,13 +3235,18 @@ ContactsDatabase::Query bindDetail(ContactsDatabase &db, quint32 contactId, quin
query.bindValue(":contactId", contactId);
query.bindValue(":name", detailValue(detail, T::FieldName));

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);
const QVariant variantValue = detailValue(detail, T::FieldData);
if (variantValue.isNull()) {
query.bindValue(":data", variantValue);
} else {
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 8fc7741

Please sign in to comment.