aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-01-20 18:52:18 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-01-20 18:52:18 +0200
commitad72d3a438129df5158b3baf91623d3ab3e21b49 (patch)
tree8b53da2a7e33b539ccb4368c644cc8f2daf7ab3a
parent715b0b5a24523556c116df7b7e5119b11d505f39 (diff)
Fix QUuid storage in PG
We need to convert it to/from big-endian RFC 4122 layout.
-rw-r--r--odb/qt/basic/pgsql/quuid-traits.hxx11
1 files changed, 9 insertions, 2 deletions
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<const char*> (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);
}
};