From a926388f73aed90d1aa9743d32ed4c049af6bf84 Mon Sep 17 00:00:00 2001 From: Constantin Michael Date: Fri, 11 Nov 2011 13:43:01 +0200 Subject: Add Oracle support for Qt profile --- odb/qt/basic-oracle.options | 14 +++++ odb/qt/basic/oracle/default-mapping.hxx | 22 ++++++++ odb/qt/basic/oracle/qbyte-array-traits.hxx | 79 ++++++++++++++++++++++++++ odb/qt/basic/oracle/qstring-traits.hxx | 77 +++++++++++++++++++++++++ odb/qt/date-time-oracle.options | 15 +++++ odb/qt/date-time/oracle/default-mapping.hxx | 29 ++++++++++ odb/qt/date-time/oracle/qdate-time-traits.hxx | 81 +++++++++++++++++++++++++++ odb/qt/date-time/oracle/qdate-traits.hxx | 76 +++++++++++++++++++++++++ odb/qt/date-time/oracle/qtime-traits.hxx | 66 ++++++++++++++++++++++ 9 files changed, 459 insertions(+) create mode 100644 odb/qt/basic-oracle.options create mode 100644 odb/qt/basic/oracle/default-mapping.hxx create mode 100644 odb/qt/basic/oracle/qbyte-array-traits.hxx create mode 100644 odb/qt/basic/oracle/qstring-traits.hxx create mode 100644 odb/qt/date-time-oracle.options create mode 100644 odb/qt/date-time/oracle/default-mapping.hxx create mode 100644 odb/qt/date-time/oracle/qdate-time-traits.hxx create mode 100644 odb/qt/date-time/oracle/qdate-traits.hxx create mode 100644 odb/qt/date-time/oracle/qtime-traits.hxx diff --git a/odb/qt/basic-oracle.options b/odb/qt/basic-oracle.options new file mode 100644 index 0000000..6e88522 --- /dev/null +++ b/odb/qt/basic-oracle.options @@ -0,0 +1,14 @@ +# file : odb/qt/basic-oracle.options +# author : Constantin Michael +# copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +# license : GNU GPL v2; see accompanying LICENSE file + +--profile qt/version + +# Include the default mapping in prologue instead of epilogue to +# allow the user to override the default mapping. +# +--odb-prologue '#include ' + +--hxx-prologue '#include ' +--hxx-prologue '#include ' diff --git a/odb/qt/basic/oracle/default-mapping.hxx b/odb/qt/basic/oracle/default-mapping.hxx new file mode 100644 index 0000000..1fe6de0 --- /dev/null +++ b/odb/qt/basic/oracle/default-mapping.hxx @@ -0,0 +1,22 @@ +// file : odb/qt/basic/oracle/default-mapping.hxx +// author : Constantin Michael +// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_QT_BASIC_ORACLE_DEFAULT_MAPPING_HXX +#define ODB_QT_BASIC_ORACLE_DEFAULT_MAPPING_HXX + +#include +#include + +// Map QString to Oracle VARCHAR2 by default. Allow NULL values by default as +// QString provides a null representation. +// +#pragma db value(QString) type("VARCHAR2(4000)") null + +// Map QByteArray to Oracle RAW by default. Allow NULL values by default as +// QByteArray provides a null representation. +// +#pragma db value(QByteArray) type("RAW(2000)") null + +#endif // ODB_QT_BASIC_ORACLE_DEFAULT_MAPPING_HXX diff --git a/odb/qt/basic/oracle/qbyte-array-traits.hxx b/odb/qt/basic/oracle/qbyte-array-traits.hxx new file mode 100644 index 0000000..58807b9 --- /dev/null +++ b/odb/qt/basic/oracle/qbyte-array-traits.hxx @@ -0,0 +1,79 @@ +// file : odb/qt/basic/oracle/qbyte-array-traits.hxx +// author : Constantin Michael +// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_QT_BASIC_ORACLE_QBYTE_ARRAY_TRAITS_HXX +#define ODB_QT_BASIC_ORACLE_QBYTE_ARRAY_TRAITS_HXX + +#include + +#include // std::memcpy +#include // std::size_t + +#include + +#include + +namespace odb +{ + namespace oracle + { + template <> + struct default_value_traits + { + typedef QByteArray value_type; + typedef QByteArray query_type; + typedef char* image_type; + + static void + set_value (QByteArray& v, + const char* b, + std::size_t n, + bool is_null) + { + if (is_null) + v = QByteArray (); + else + { + // Note that we cannot use replace() here since a suitable + // overload was only added in Qt 4.7. + // + v.resize (static_cast (n)); + std::memcpy (v.data (), b, n); + } + } + + static void + set_image (char* b, + std::size_t c, + std::size_t& n, + bool& is_null, + const QByteArray& v) + { + if (v.isNull ()) + is_null = true; + else + { + is_null = false; + + n = static_cast (v.size ()); + + //@@ Assert or throw? + // + assert (n <= c); + + std::memcpy (b, v.data (), n); + } + } + }; + + template <> + struct default_type_traits + { + static const database_type_id db_type_id = id_raw; + }; + } +} + +#endif // ODB_QT_BASIC_ORACLE_QBYTE_ARRAY_TRAITS_HXX diff --git a/odb/qt/basic/oracle/qstring-traits.hxx b/odb/qt/basic/oracle/qstring-traits.hxx new file mode 100644 index 0000000..729de62 --- /dev/null +++ b/odb/qt/basic/oracle/qstring-traits.hxx @@ -0,0 +1,77 @@ +// file : odb/qt/basic/oracle/qstring-traits.hxx +// author : Constantin Michael +// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_QT_BASIC_ORACLE_QSTRING_TRAITS_HXX +#define ODB_QT_BASIC_ORACLE_QSTRING_TRAITS_HXX + +#include + +#include // std::memcpy +#include // std::size_t + +#include + +#include + +namespace odb +{ + namespace oracle + { + template <> + struct default_value_traits + { + public: + typedef QString value_type; + typedef QString query_type; + typedef char* image_type; + + static void + set_value (QString& v, + const char* b, + std::size_t n, + bool is_null) + { + if (is_null) + v = QString (); + else + v = QString::fromUtf8 (b, static_cast (n)); + } + + static void + set_image (char* b, + std::size_t c, + std::size_t& n, + bool& is_null, + const QString& v) + { + if (v.isNull ()) + is_null = true; + else + { + is_null = false; + + const QByteArray& a (v.toUtf8 ()); + n = static_cast (a.size ()); + + //@@ Assert or throw? + // + assert (n <= c); + + std::memcpy (b, a.data (), n); + } + } + }; + + template <> + struct default_type_traits + { + static const database_type_id db_type_id = id_string; + }; + } +} + +#include + +#endif // ODB_QT_BASIC_ORACLE_QSTRING_TRAITS_HXX diff --git a/odb/qt/date-time-oracle.options b/odb/qt/date-time-oracle.options new file mode 100644 index 0000000..b57a6f5 --- /dev/null +++ b/odb/qt/date-time-oracle.options @@ -0,0 +1,15 @@ +# file : odb/qt/date-time-oracle.options +# author : Constantin Michael +# copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +# license : GNU GPL v2; see accompanying LICENSE file + +--profile qt/version + +# Include the default mapping in prologue instead of epilogue to +# allow the user to override the default mapping. +# +--odb-prologue '#include ' + +--hxx-prologue '#include ' +--hxx-prologue '#include ' +--hxx-prologue '#include ' diff --git a/odb/qt/date-time/oracle/default-mapping.hxx b/odb/qt/date-time/oracle/default-mapping.hxx new file mode 100644 index 0000000..4411934 --- /dev/null +++ b/odb/qt/date-time/oracle/default-mapping.hxx @@ -0,0 +1,29 @@ +// file : odb/qt/date-time/oracle/default-mapping.hxx +// author : Constantin Michael +// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_QT_DATE_TIME_ORACLE_DEFAULT_MAPPING_HXX +#define ODB_QT_DATE_TIME_ORACLE_DEFAULT_MAPPING_HXX + +#include +#include +#include + +// Map QDate to Oracle DATE by default. QDate provides a null representation +// so allow NULL values by default. +// +#pragma db value(QDate) type("DATE") null + +// Map QTime to Oracle INTERVAL DAY(0) TO SECOND by default. QTime can only +// represent clock times with a maximum precision of milliseconds. QTime +// provides a null representation so allow NULL values by default. +// +#pragma db value(QTime) type("INTERVAL DAY(0) TO SECOND") null + +// Map QDateTime to ORACLE TIMESTAMP by default. QDateTime provides a null +// representation so allow NULL values by default. +// +#pragma db value(QDateTime) type("TIMESTAMP(6)") null + +#endif // ODB_QT_DATE_TIME_ORACLE_DEFAULT_MAPPING_HXX diff --git a/odb/qt/date-time/oracle/qdate-time-traits.hxx b/odb/qt/date-time/oracle/qdate-time-traits.hxx new file mode 100644 index 0000000..3ecb268 --- /dev/null +++ b/odb/qt/date-time/oracle/qdate-time-traits.hxx @@ -0,0 +1,81 @@ +// file : odb/qt/date-time/oracle/qdate-time-traits.hxx +// author : Constantin Michael +// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_QT_DATE_TIME_ORACLE_QDATETIME_TRAITS_HXX +#define ODB_QT_DATE_TIME_ORACLE_QDATETIME_TRAITS_HXX + +#include + +#include + +#include + +namespace odb +{ + namespace oracle + { + template <> + struct default_value_traits + { + typedef QDateTime value_type; + typedef QDateTime query_type; + typedef datetime image_type; + + static void + set_value (QDateTime& v, const datetime& i, bool is_null) + { + if (is_null) + // Default constructor creates a null QDateTime. + // + v = QDateTime (); + else + { + sb2 y (0); + ub1 m (0), d (0), h (0), min (0), s (0); + ub4 ns (0); + i.get (y, m, d, h, min, s, ns); + + v = QDateTime (QDate (static_cast (y), + static_cast (m), + static_cast (d)), + QTime (static_cast (h), + static_cast (min), + static_cast (s), + static_cast (ns / 1000))); + } + } + + static void + set_image (datetime& i, bool& is_null, const QDateTime& v) + { + if (v.isNull ()) + is_null = true; + else + { + is_null = false; + + const QDate& d (v.date ()); + const QTime& t (v.time ()); + + i.set (static_cast (d.year ()), + static_cast (d.month ()), + static_cast (d.day ()), + static_cast (t.hour ()), + static_cast (t.minute ()), + static_cast (t.second ()), + static_cast (t.msec () * 1000)); + } + } + }; + + template <> + struct default_type_traits + { + static const database_type_id db_type_od = id_timestamp; + }; + } +} + +#endif // ODB_QT_DATE_TIME_ORACLE_QDATETIME_TRAITS_HXX diff --git a/odb/qt/date-time/oracle/qdate-traits.hxx b/odb/qt/date-time/oracle/qdate-traits.hxx new file mode 100644 index 0000000..4d4f9db --- /dev/null +++ b/odb/qt/date-time/oracle/qdate-traits.hxx @@ -0,0 +1,76 @@ +// file : odb/qt/date-time/oracle/qdate-traits.hxx +// author : Constantin Michael +// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_QT_DATE_TIME_ORACLE_QDATE_TRAITS_HXX +#define ODB_QT_DATE_TIME_ORACLE_QDATE_TRAITS_HXX + +#include + +#include + +#include + +#include + +#include + +namespace odb +{ + namespace oracle + { + template <> + struct default_value_traits + { + typedef QDate value_type; + typedef QDate query_type; + typedef char* image_type; + + static void + set_value (QDate& v, const char* b, bool is_null) + { + if (is_null) + // A null QDate value is equivalent to an invalid QDate value. + // Set v to an invalid date to represent null. + // + v.setDate (0, 0, 0); + else + { + short y (0); + unsigned char m (0), d (0), h (0), min (0), s (0); + details::get_date (b, y, m, d, h, min, s); + + v.setDate (y, m, d); + } + } + + static void + set_image (char* b, bool& is_null, const QDate& v) + { + if (v.isNull ()) + is_null = true; + else + { + is_null = false; + + details::set_date (b, + static_cast (v.year ()), + static_cast (v.month ()), + static_cast (v.day ()), + 0, + 0, + 0); + } + } + }; + + template <> + struct default_type_traits + { + static const database_type_id db_type_id = id_date; + }; + } +} + +#endif // ODB_QT_DATE_TIME_ORACLE_QDATE_TRAITS_HXX diff --git a/odb/qt/date-time/oracle/qtime-traits.hxx b/odb/qt/date-time/oracle/qtime-traits.hxx new file mode 100644 index 0000000..b56bad5 --- /dev/null +++ b/odb/qt/date-time/oracle/qtime-traits.hxx @@ -0,0 +1,66 @@ +// file : odb/qt/date-time/oracle/qtime-traits.hxx +// author : Constantin Michael +// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_QT_DATE_TIME_ORACLE_QTIME_TRAITS_HXX +#define ODB_QT_DATE_TIME_ORACLE_QTIME_TRAITS_HXX + +#include + +#include + +#include + +namespace odb +{ + namespace oracle + { + template <> + struct default_value_traits + { + typedef QTime value_type; + typedef QTime query_type; + typedef interval_ds image_type; + + static void + set_value (QTime& v, const interval_ds& i, bool is_null) + { + if (is_null) + // A null QTime value is equivalent to an invalid QTime value. + // Set v to an invalid time to represent null (hour value of + // a valid time must be in the range 0-23). + // + v.setHMS (24, 0, 0); + else + { + sb4 d (0), h (0), m (0), s (0), ns (0); + i.get (d, h, m, s, ns); + + v.setHMS (h, m, s, ns / 1000); + } + } + + static void + set_image (interval_ds& i, bool& is_null, const QTime& v) + { + if (v.isNull ()) + is_null = true; + else + { + is_null = false; + + i.set (0, v.hour (), v.minute (), v.second (), v.msec () * 1000); + } + } + }; + + template <> + struct default_type_traits + { + static const database_type_id db_type_id = id_interval_ds; + }; + } +} + +#endif // ODB_QT_DATE_TIME_ORACLE_QTIME_TRAITS_HXX -- cgit v1.1