SQL/Mimer: simplify uuid conversion

Simplify converting a QUuid to a rfc4122 representation by using the
built-in toRfc4122() function and don't allocate a temporary QByteArray
when converting it back from rfc4122 to a QUuid.
As a drive-by make sure to not detach when converting a QByteArray to a
blob.

Change-Id: Ib8fc7744952377d14ef39c0d901a6a8419eb018d
Reviewed-by: Fredrik Ålund <fredrik.alund@mimer.com>
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
(cherry picked from commit 814e4e1cbe6e4a625625942c70b394aa6455fb19)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Christian Ehrlicher 2024-10-23 19:47:28 +02:00 committed by Qt Cherry-pick Bot
parent cb0ac3d471
commit 81ba262a62

View File

@ -845,7 +845,7 @@ QVariant QMimerSQLResult::data(int i)
err, QSqlError::StatementError, d->drv_d_func()));
return QVariant(QMetaType(type), nullptr);
}
const QByteArray uuidByteArray = QByteArray(reinterpret_cast<char *>(uuidChar), 16);
const auto uuidByteArray = QByteArrayView(reinterpret_cast<char *>(uuidChar), 16);
return QUuid::fromRfc4122(uuidByteArray);
}
case MimerColumnTypes::Unknown:
@ -1084,8 +1084,7 @@ bool QMimerSQLResult::exec()
break;
}
case MimerColumnTypes::Uuid: {
const QByteArray uuidArray =
QByteArray::fromHex(val.toUuid().toString(QUuid::WithoutBraces).toLatin1());
const QByteArray uuidArray = val.toUuid().toRfc4122();
const unsigned char *uuid =
reinterpret_cast<const unsigned char *>(uuidArray.constData());
err = MimerSetUUID(d->statementhandle, i + 1, uuid);
@ -1152,7 +1151,7 @@ bool QMimerSQLResult::exec()
break;
}
case MimerColumnTypes::Blob: {
QByteArray blobArr = val.toByteArray();
const QByteArray blobArr = val.toByteArray();
const char *blobData = blobArr.constData();
qsizetype size = blobArr.size();
err = MimerSetLob(d->statementhandle, i + 1, size, &d->lobhandle);