From 32d382ddfbfac28316a9048e22f8493f66c51805 Mon Sep 17 00:00:00 2001 From: Constantin Michael Date: Fri, 22 Jul 2011 10:02:42 +0200 Subject: Correct QString null semantics in MySQL and SQLite profiles --- odb/qt/basic/mysql/qstring-traits.hxx | 17 ++++++++++------- odb/qt/basic/sqlite/qstring-traits.hxx | 17 +++++++++++------ 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/odb/qt/basic/mysql/qstring-traits.hxx b/odb/qt/basic/mysql/qstring-traits.hxx index 922c4c3..8596d37 100644 --- a/odb/qt/basic/mysql/qstring-traits.hxx +++ b/odb/qt/basic/mysql/qstring-traits.hxx @@ -45,15 +45,18 @@ namespace odb bool& is_null, const QString& v) { - is_null = false; - - const QByteArray& a (v.toUtf8 ()); - n = static_cast (a.size ()); + if (v.isNull ()) + is_null = true; + else + { + const QByteArray& a (v.toUtf8 ()); + n = static_cast (a.size ()); - if (n > b.capacity ()) - b.capacity (n); + if (n > b.capacity ()) + b.capacity (n); - std::memcpy (b.data (), a.data (), n); + std::memcpy (b.data (), a.data (), n); + } } }; diff --git a/odb/qt/basic/sqlite/qstring-traits.hxx b/odb/qt/basic/sqlite/qstring-traits.hxx index 5014aaf..fdcbbfe 100644 --- a/odb/qt/basic/sqlite/qstring-traits.hxx +++ b/odb/qt/basic/sqlite/qstring-traits.hxx @@ -46,15 +46,20 @@ namespace odb bool& is_null, const QString& v) { - is_null = false; + if (v.isNull ()) + is_null = true; + else + { + is_null = false; - const QByteArray& a (v.toUtf8 ()); - n = static_cast (a.size ()); + const QByteArray& a (v.toUtf8 ()); + n = static_cast (a.size ()); - if (n > b.capacity ()) - b.capacity (n); + if (n > b.capacity ()) + b.capacity (n); - std::memcpy (b.data (), a.data (), n); + std::memcpy (b.data (), a.data (), n); + } } }; -- cgit v1.1