diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2012-09-10 12:12:06 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2012-09-10 12:12:06 +0200 |
commit | 173c4e96a98a2382166878a2fa7586470670e00a (patch) | |
tree | d228860a1395b436454afc94b70bd0a6b7c2fc63 | |
parent | 9fe985cdce9f0e1f9bee0e3cfc7a834b842f1906 (diff) |
Add support for alternative UTF-16 image for TEXT in SQLite
Use it to handle QString and support std::wstring on Windows.
-rw-r--r-- | odb/qt/basic/sqlite/qstring-traits.hxx | 19 |
1 files 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<QString, id_text> + { + 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 <QString, id_text> { public: @@ -36,7 +46,8 @@ namespace odb if (is_null) v = QString (); else - v = QString::fromUtf8 (b.data (), static_cast<int> (n)); + v.setUtf16 (reinterpret_cast<const ushort*> (b.data ()), + static_cast<int> (n / 2)); // In characters. } static void @@ -50,14 +61,12 @@ namespace odb else { is_null = false; - - const QByteArray& a (v.toUtf8 ()); - n = static_cast<std::size_t> (a.size ()); + n = static_cast<std::size_t> (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); } } }; |