From ad72d3a438129df5158b3baf91623d3ab3e21b49 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 20 Jan 2016 18:52:18 +0200 Subject: Fix QUuid storage in PG We need to convert it to/from big-endian RFC 4122 layout. --- odb/qt/basic/pgsql/quuid-traits.hxx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'odb/qt/basic/pgsql/quuid-traits.hxx') diff --git a/odb/qt/basic/pgsql/quuid-traits.hxx b/odb/qt/basic/pgsql/quuid-traits.hxx index 3af06cf..b500fe5 100644 --- a/odb/qt/basic/pgsql/quuid-traits.hxx +++ b/odb/qt/basic/pgsql/quuid-traits.hxx @@ -25,11 +25,18 @@ namespace odb typedef value_type query_type; typedef unsigned char* image_type; + // PostgreSQL binary UUID representation is big-endian in the RFC 4122, + // section 4.1.2 order. While Qt provides (since 4.8) to/fromRfc4122(), + // they both incur a memory allocation (by QByteArray) which we could + // avoid, if we did it ourselves. + // + static void set_value (value_type& v, const unsigned char* i, bool is_null) { if (!is_null) - std::memcpy (&v.data1, i, 16); + v = QUuid::fromRfc4122 ( + QByteArray (reinterpret_cast (i), 16)); else v = QUuid (); } @@ -42,7 +49,7 @@ namespace odb is_null = is_null && v.isNull (); if (!is_null) - std::memcpy (i, &v.data1, 16); + std::memcpy (i, v.toRfc4122 ().constData (), 16); } }; -- cgit v1.1