From 173c4e96a98a2382166878a2fa7586470670e00a Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 10 Sep 2012 12:12:06 +0200 Subject: Add support for alternative UTF-16 image for TEXT in SQLite Use it to handle QString and support std::wstring on Windows. --- odb/qt/basic/sqlite/qstring-traits.hxx | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/odb/qt/basic/sqlite/qstring-traits.hxx b/odb/qt/basic/sqlite/qstring-traits.hxx index 943cc8a..a60088d 100644 --- a/odb/qt/basic/sqlite/qstring-traits.hxx +++ b/odb/qt/basic/sqlite/qstring-traits.hxx @@ -20,6 +20,16 @@ namespace odb namespace sqlite { template <> + struct image_traits + { + typedef details::buffer image_type; + + // Use UTF-16 binding for QString. + // + static const bind::buffer_type bind_value = bind::text16; + }; + + template <> struct default_value_traits { public: @@ -36,7 +46,8 @@ namespace odb if (is_null) v = QString (); else - v = QString::fromUtf8 (b.data (), static_cast (n)); + v.setUtf16 (reinterpret_cast (b.data ()), + static_cast (n / 2)); // In characters. } static void @@ -50,14 +61,12 @@ namespace odb else { is_null = false; - - const QByteArray& a (v.toUtf8 ()); - n = static_cast (a.size ()); + n = static_cast (v.size ()) * 2; // In bytes. if (n > b.capacity ()) b.capacity (n); - std::memcpy (b.data (), a.data (), n); + std::memcpy (b.data (), v.utf16 (), n); } } }; -- cgit v1.1