diff options
author | Constantin Michael <constantin@codesynthesis.com> | 2011-11-11 13:43:01 +0200 |
---|---|---|
committer | Constantin Michael <constantin@codesynthesis.com> | 2011-11-11 13:43:01 +0200 |
commit | a926388f73aed90d1aa9743d32ed4c049af6bf84 (patch) | |
tree | 028846d9d85a194bd6f024f790660c566f223ea9 | |
parent | 2a429f33bbeffa388fd6c266e1c88a9f188256c5 (diff) |
Add Oracle support for Qt profile
-rw-r--r-- | odb/qt/basic-oracle.options | 14 | ||||
-rw-r--r-- | odb/qt/basic/oracle/default-mapping.hxx | 22 | ||||
-rw-r--r-- | odb/qt/basic/oracle/qbyte-array-traits.hxx | 79 | ||||
-rw-r--r-- | odb/qt/basic/oracle/qstring-traits.hxx | 77 | ||||
-rw-r--r-- | odb/qt/date-time-oracle.options | 15 | ||||
-rw-r--r-- | odb/qt/date-time/oracle/default-mapping.hxx | 29 | ||||
-rw-r--r-- | odb/qt/date-time/oracle/qdate-time-traits.hxx | 81 | ||||
-rw-r--r-- | odb/qt/date-time/oracle/qdate-traits.hxx | 76 | ||||
-rw-r--r-- | odb/qt/date-time/oracle/qtime-traits.hxx | 66 |
9 files changed, 459 insertions, 0 deletions
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 <constantin@codesynthesis.com> +# 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 <odb/qt/basic/oracle/default-mapping.hxx>' + +--hxx-prologue '#include <odb/qt/basic/oracle/qstring-traits.hxx>' +--hxx-prologue '#include <odb/qt/basic/oracle/qbyte-array-traits.hxx>' 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 <constantin@codesynthesis.com> +// 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 <QtCore/QString> +#include <QtCore/QByteArray> + +// 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 <constantin@codesynthesis.com> +// 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 <odb/pre.hxx> + +#include <cstring> // std::memcpy +#include <cstddef> // std::size_t + +#include <QtCore/QByteArray> + +#include <odb/oracle/traits.hxx> + +namespace odb +{ + namespace oracle + { + template <> + struct default_value_traits<QByteArray, id_raw> + { + 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<int> (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<std::size_t> (v.size ()); + + //@@ Assert or throw? + // + assert (n <= c); + + std::memcpy (b, v.data (), n); + } + } + }; + + template <> + struct default_type_traits<QByteArray> + { + 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 <constantin@codesynthesis.com> +// 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 <odb/pre.hxx> + +#include <cstring> // std::memcpy +#include <cstddef> // std::size_t + +#include <QtCore/QString> + +#include <odb/oracle/traits.hxx> + +namespace odb +{ + namespace oracle + { + template <> + struct default_value_traits <QString, id_string> + { + 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<int> (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<std::size_t> (a.size ()); + + //@@ Assert or throw? + // + assert (n <= c); + + std::memcpy (b, a.data (), n); + } + } + }; + + template <> + struct default_type_traits<QString> + { + static const database_type_id db_type_id = id_string; + }; + } +} + +#include <odb/post.hxx> + +#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 <constantin@codesynthesis.com> +# 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 <odb/qt/date-time/oracle/default-mapping.hxx>' + +--hxx-prologue '#include <odb/qt/date-time/oracle/qdate-traits.hxx>' +--hxx-prologue '#include <odb/qt/date-time/oracle/qtime-traits.hxx>' +--hxx-prologue '#include <odb/qt/date-time/oracle/qdate-time-traits.hxx>' 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 <constantin@codesynthesis.com> +// 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 <QtCore/QDate> +#include <QtCore/QTime> +#include <QtCore/QDateTime> + +// 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 <constantin@codesynthesis.com> +// 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 <odb/pre.hxx> + +#include <QtCore/QDateTime> + +#include <odb/oracle/traits.hxx> + +namespace odb +{ + namespace oracle + { + template <> + struct default_value_traits<QDateTime, id_timestamp> + { + 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<int> (y), + static_cast<int> (m), + static_cast<int> (d)), + QTime (static_cast<int> (h), + static_cast<int> (min), + static_cast<int> (s), + static_cast<int> (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<sb2> (d.year ()), + static_cast<ub1> (d.month ()), + static_cast<ub1> (d.day ()), + static_cast<ub1> (t.hour ()), + static_cast<ub1> (t.minute ()), + static_cast<ub1> (t.second ()), + static_cast<ub4> (t.msec () * 1000)); + } + } + }; + + template <> + struct default_type_traits<QDateTime> + { + 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 <constantin@codesynthesis.com> +// 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 <odb/pre.hxx> + +#include <QtCore/QDate> + +#include <odb/oracle/traits.hxx> + +#include <odb/oracle/details/date.hxx> + +#include <odb/qt/date-time/exceptions.hxx> + +namespace odb +{ + namespace oracle + { + template <> + struct default_value_traits<QDate, id_date> + { + 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<short> (v.year ()), + static_cast<unsigned char> (v.month ()), + static_cast<unsigned char> (v.day ()), + 0, + 0, + 0); + } + } + }; + + template <> + struct default_type_traits<QDate> + { + 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 <constantin@codesynthesis.com> +// 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 <odb/pre.hxx> + +#include <QtCore/QTime> + +#include <odb/oracle/traits.hxx> + +namespace odb +{ + namespace oracle + { + template <> + struct default_value_traits<QTime, id_interval_ds> + { + 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<QTime> + { + static const database_type_id db_type_id = id_interval_ds; + }; + } +} + +#endif // ODB_QT_DATE_TIME_ORACLE_QTIME_TRAITS_HXX |