aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--odb/qt/mysql/default-mapping.hxx15
-rw-r--r--odb/qt/mysql/qbytearray-traits.hxx71
-rw-r--r--odb/qt/mysql/qdate-traits.hxx55
-rw-r--r--odb/qt/mysql/qdatetime-traits.hxx108
-rw-r--r--odb/qt/mysql/qstring-traits.hxx14
-rw-r--r--odb/qt/mysql/qtime-traits.hxx55
6 files changed, 311 insertions, 7 deletions
diff --git a/odb/qt/mysql/default-mapping.hxx b/odb/qt/mysql/default-mapping.hxx
index 6647bbd..6a948c4 100644
--- a/odb/qt/mysql/default-mapping.hxx
+++ b/odb/qt/mysql/default-mapping.hxx
@@ -7,9 +7,24 @@
#define ODB_QT_MYSQL_DEFAULT_MAPPING_HXX
#include <QString>
+#include <QDate>
+#include <QTime>
+#include <QDateTime>
// Map QString to MySQL TEXT by default.
//
#pragma db value(QString) type("VARCHAR(56) NOT NULL")
+// Map QDate to MySQL DATE by default.
+//
+#pragma db value(QDate) type("DATE")
+
+// Map QTime to MySQL TIME by default.
+//
+#pragma db value(QTime) type("TIME")
+
+// Map QTime to MySQL DATETIME by default.
+//
+#pragma db value(QDateTime) type("DATETIME")
+
#endif // ODB_QT_MYSQL_DEFAULT_MAPPING_HXX
diff --git a/odb/qt/mysql/qbytearray-traits.hxx b/odb/qt/mysql/qbytearray-traits.hxx
new file mode 100644
index 0000000..d94bf44
--- /dev/null
+++ b/odb/qt/mysql/qbytearray-traits.hxx
@@ -0,0 +1,71 @@
+// file : odb/qt/mysql/qbytearray-traits.hxx
+// author : Constantin Michael <constantin@codesynthesis.com>
+// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_QT_MYSQL_QBYTEARRAY_TRAITS_HXX
+#define ODB_QT_MYSQL_QBYTEARRAY_TRAITS_HXX
+
+#include <odb/pre.hxx>
+
+#include <cstring> // std::memcpy
+#include <cstddef> // std::size_t
+
+#include <QByteArray>
+
+#include <odb/details/buffer.hxx>
+#include <odb/mysql/traits.hxx>
+
+namespace odb
+{
+ namespace mysql
+ {
+ template <>
+ class default_value_traits<QByteArray, details::buffer, id_blob>
+ {
+ public:
+ typedef QByteArray value_type;
+ typedef QByteArray query_type;
+ typedef details::buffer image_type;
+
+ static void
+ set_value (QByteArray& v,
+ const details::buffer& b,
+ std::size_t n,
+ bool is_null)
+ {
+ if (is_null)
+ v = QByteArray ();
+ else
+ {
+ if (v.capacity () < n + 1)
+ v.reserve (n + 1);
+
+ std::memcpy (v.data (), b.data (), n);
+ v.resize (n);
+ }
+ }
+
+ static void
+ set_image (details::buffer& b,
+ std::size_t& n,
+ bool& is_null,
+ const QByteArray& v)
+ {
+ if (v.is_null)
+ is_null = true;
+ else
+ {
+ n = v.size ();
+ if (n > b.capacity ())
+ b.capacity (n);
+
+ if (n != 0)
+ std::memcpy (v.data (), b.data (), n);
+ }
+ }
+ };
+ }
+}
+
+#endif // ODB_QT_MYSQL_QBYTEARRAY_TRAITS_HXX
diff --git a/odb/qt/mysql/qdate-traits.hxx b/odb/qt/mysql/qdate-traits.hxx
new file mode 100644
index 0000000..168e6f9
--- /dev/null
+++ b/odb/qt/mysql/qdate-traits.hxx
@@ -0,0 +1,55 @@
+// file : odb/qt/mysql/qdate-traits.hxx
+// author : Constantin Michael <constantin@codesynthesis.com>
+// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_QT_MYSQL_QDATE_TRAITS_HXX
+#define ODB_QT_MYSQL_QDATE_TRAITS_HXX
+
+#include <odb/pre.hxx>
+
+#include <QDate>
+
+#include <odb/mysql/traits.hxx>
+
+namespace odb
+{
+ namespace mysql
+ {
+ template <>
+ class default_value_traits<QDate, MYSQL_TIME, id_date>
+ {
+ public:
+ typedef QDate value_type;
+ typedef QDate query_type;
+ typedef MYSQL_TIME image_type;
+
+ static void
+ set_value (QDate& v, const MYSQL_TIME& i, bool is_null)
+ {
+ if (is_null)
+ // Set the date to be invalid.
+ //
+ v.setDate (0, 0, 0);
+ else
+ v.setDate (i.year, i.month, i.day);
+ }
+
+ static void
+ set_image (MYSQL_TIME& i, bool& is_null, const QDate& v)
+ {
+ if (v.isNull ())
+ is_null = true;
+ else
+ {
+ is_null = false;
+ i.year = v.year ();
+ i.month = v.month ();
+ i.day = v.day ();
+ }
+ }
+ };
+ }
+}
+
+#endif // ODB_QT_MYSQL_QDATE_TRAITS_HXX
diff --git a/odb/qt/mysql/qdatetime-traits.hxx b/odb/qt/mysql/qdatetime-traits.hxx
new file mode 100644
index 0000000..2ed8139
--- /dev/null
+++ b/odb/qt/mysql/qdatetime-traits.hxx
@@ -0,0 +1,108 @@
+// file : odb/qt/mysql/qdatetime-traits.hxx
+// author : Constantin Michael <constantin@codesynthesis.com>
+// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_QT_MYSQL_QDATETIME_TRAITS_HXX
+#define ODB_QT_MYSQL_QDATETIME_TRAITS_HXX
+
+#include <odb/pre.hxx>
+
+#include <QDateTime>
+
+#include <odb/mysql/traits.hxx>
+
+namespace odb
+{
+ namespace mysql
+ {
+ template <>
+ class default_value_traits<QDateTime, MYSQL_TIME, id_datetime>
+ {
+ public:
+ typedef QDateTime value_type;
+ typedef QDateTime query_type;
+ typedef MYSQL_TIME image_type;
+
+ static void
+ set_value (QDateTime& v, const MYSQL_TIME& i, bool is_null)
+ {
+ if (is_null)
+ // Set the date part to be invalid.
+ //
+ v.setDate (QDate (0, 0, 0));
+ else
+ {
+ v.setDate (QDate (i.year, i.month, i.day));
+ v.setTime (QTime (i.hour, i.minute, i.second));
+ }
+ }
+
+ static void
+ set_image (MYSQL_TIME& i, bool& is_null, const QDateTime& v)
+ {
+ if (v.is_null ())
+ is_null = true;
+ else
+ {
+ is_null = false;
+
+ const QDate& d (v.date ());
+ i.year = d.year;
+ i.month = d.month;
+ i.day = d.day;
+
+ const QTime& t (v.time ());
+ i.hour = t.hour ();
+ i.minute = t.minute ();
+ i.second = t.second ();
+ }
+ }
+ };
+
+ class default_value_traits<QDateTime, MYSQL_TIME, id_timestamp>
+ {
+ public:
+ typedef QDateTime value_type;
+ typedef QDateTime query_type;
+ typedef MYSQL_TIME image_type;
+
+ static void
+ set_value (QDateTime& v, const MYSQL_TIME& i, bool is_null)
+ {
+ if (is_null)
+ // Set the date part to be invalid.
+ //
+ v.setDate (QDate (0, 0, 0));
+ else
+ {
+ v.setDate (QDate (i.year, i.month, i.day));
+ v.setDate (QTime (i.hour, i.minute, i.second));
+ }
+ }
+
+ static void
+ set_image (MYSQL_TIME& i, bool& is_null, const QDateTime& v)
+ {
+ if (v.is_null ())
+ is_null = true;
+ else
+ {
+ is_null = false;
+
+ const QDate& d (v.date ());
+ i.year = d.year;
+ i.month = d.month;
+ i.day = d.day;
+
+ const QTime& t (v.time ());
+ i.hour = t.hour ();
+ i.minute = t.minute ();
+ i.second = t.second ();
+ }
+ }
+ };
+ }
+}
+
+#endif // ODB_QT_MYSQL_QDATETIME_TRAITS_HXX
diff --git a/odb/qt/mysql/qstring-traits.hxx b/odb/qt/mysql/qstring-traits.hxx
index d179972..facb569 100644
--- a/odb/qt/mysql/qstring-traits.hxx
+++ b/odb/qt/mysql/qstring-traits.hxx
@@ -8,19 +8,19 @@
#include <odb/pre.hxx>
+#include <cstring> // std::memcpy
#include <cstddef> // std::size_t
#include <QString>
#include <odb/details/buffer.hxx>
#include <odb/mysql/traits.hxx>
-#include <odb/qt/details/export.hxx>
namespace odb
{
namespace mysql
{
- class LIBODB_QT_EXPORT qstring_value_traits
+ class qstring_value_traits
{
public:
typedef QString value_type;
@@ -54,30 +54,30 @@ namespace odb
b.capacity (n);
if (n != 0)
- memcpy (b.data (), a.data (), n);
+ std::memcpy (b.data (), a.data (), n);
}
};
template <>
- struct LIBODB_QT_EXPORT default_value_traits<
+ struct default_value_traits<
QString, details::buffer, id_string>: qstring_value_traits
{
};
template <>
- struct LIBODB_QT_EXPORT default_value_traits<
+ struct default_value_traits<
QString, details::buffer, id_decimal>: qstring_value_traits
{
};
template <>
- struct LIBODB_QT_EXPORT default_value_traits<
+ struct default_value_traits<
QString, details::buffer, id_enum>: qstring_value_traits
{
};
template <>
- struct LIBODB_QT_EXPORT default_value_traits<
+ struct default_value_traits<
QString, details::buffer, id_set>: qstring_value_traits
{
};
diff --git a/odb/qt/mysql/qtime-traits.hxx b/odb/qt/mysql/qtime-traits.hxx
new file mode 100644
index 0000000..9789114
--- /dev/null
+++ b/odb/qt/mysql/qtime-traits.hxx
@@ -0,0 +1,55 @@
+// file : odb/qt/mysql/qtime-traits.hxx
+// author : Constantin Michael <constantin@codesynthesis.com>
+// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_QT_MYSQL_QTIME_TRAITS_HXX
+#define ODB_QT_MYSQL_QTIME_TRAITS_HXX
+
+#include <odb/pre.hxx>
+
+#include <QTime>
+
+#include <odb/mysql/traits.hxx>
+
+namespace odb
+{
+ namespace mysql
+ {
+ template <>
+ class default_value_traits<QTime, MYSQL_TIME, id_time>
+ {
+ public:
+ typedef QTime value_type;
+ typedef QTime query_type;
+ typedef MYSQL_TIME image_type;
+
+ static void
+ set_value (QTime& v, const MYSQL_TIME& i, bool is_null)
+ {
+ if (is_null)
+ // Set the time to be invalid.
+ //
+ v.setHMS (24, 0, 0);
+ else
+ v.setHMS (i.hour, i.minute, i.second);
+ }
+
+ static void
+ set_image (MYSQL_TIME& i, bool& is_null, const QTime& v)
+ {
+ if (v.isNull ())
+ is_null = true;
+ else
+ {
+ is_null = false;
+ i.hour = v.hour ();
+ i.minute = v.minute ();
+ i.second = v.second ();
+ }
+ }
+ };
+ }
+}
+
+#endif // ODB_QT_MYSQL_QTIME_TRAITS_HXX