From 621bc135b9825fc9f18ada204f67d3800c5f6fda Mon Sep 17 00:00:00 2001 From: Constantin Michael Date: Thu, 31 Mar 2011 15:36:02 +0200 Subject: Complete qt/basic and qt/date-time implementations --- README | 2 +- odb/qt.options | 9 +- odb/qt/basic-mysql.options | 11 +++ odb/qt/basic-sqlite.options | 11 +++ odb/qt/basic/mysql/default-mapping.hxx | 24 +++++ odb/qt/basic/mysql/qbyte-array-traits.hxx | 67 ++++++++++++++ odb/qt/basic/mysql/qstring-traits.hxx | 94 +++++++++++++++++++ odb/qt/basic/sqlite/default-mapping.hxx | 22 +++++ odb/qt/basic/sqlite/qbyte-array-traits.hxx | 72 +++++++++++++++ odb/qt/basic/sqlite/qstring-traits.hxx | 71 ++++++++++++++ odb/qt/config.h.in | 62 ------------- odb/qt/date-time-mysql.options | 12 +++ odb/qt/date-time-sqlite.options | 12 +++ odb/qt/date-time/exceptions.cxx | 21 +++++ odb/qt/date-time/exceptions.hxx | 31 +++++++ odb/qt/date-time/mysql/default-mapping.hxx | 28 ++++++ odb/qt/date-time/mysql/qdate-time-traits.hxx | 127 ++++++++++++++++++++++++++ odb/qt/date-time/mysql/qdate-traits.hxx | 68 ++++++++++++++ odb/qt/date-time/mysql/qtime-traits.hxx | 69 ++++++++++++++ odb/qt/date-time/sqlite/default-mapping.hxx | 28 ++++++ odb/qt/date-time/sqlite/qdate-time-traits.hxx | 123 +++++++++++++++++++++++++ odb/qt/date-time/sqlite/qdate-traits.hxx | 126 +++++++++++++++++++++++++ odb/qt/date-time/sqlite/qtime-traits.hxx | 118 ++++++++++++++++++++++++ odb/qt/dummy.cxx | 14 --- odb/qt/dummy.hxx | 12 --- odb/qt/exception.hxx | 2 +- odb/qt/libodb-qt-vc10.vcxproj | 8 +- odb/qt/libodb-qt-vc9.vcproj | 8 +- odb/qt/makefile | 2 +- odb/qt/mysql/default-mapping.hxx | 30 ------ odb/qt/mysql/qbytearray-traits.hxx | 71 -------------- odb/qt/mysql/qdate-traits.hxx | 55 ----------- odb/qt/mysql/qdatetime-traits.hxx | 109 ---------------------- odb/qt/mysql/qstring-traits.hxx | 95 ------------------- odb/qt/mysql/qtime-traits.hxx | 55 ----------- odb/qt/version.hxx | 6 +- odb/qt/version.options | 2 +- version | 2 +- 38 files changed, 1153 insertions(+), 526 deletions(-) create mode 100644 odb/qt/basic-mysql.options create mode 100644 odb/qt/basic-sqlite.options create mode 100644 odb/qt/basic/mysql/default-mapping.hxx create mode 100644 odb/qt/basic/mysql/qbyte-array-traits.hxx create mode 100644 odb/qt/basic/mysql/qstring-traits.hxx create mode 100644 odb/qt/basic/sqlite/default-mapping.hxx create mode 100644 odb/qt/basic/sqlite/qbyte-array-traits.hxx create mode 100644 odb/qt/basic/sqlite/qstring-traits.hxx delete mode 100644 odb/qt/config.h.in create mode 100644 odb/qt/date-time-mysql.options create mode 100644 odb/qt/date-time-sqlite.options create mode 100644 odb/qt/date-time/exceptions.cxx create mode 100644 odb/qt/date-time/exceptions.hxx create mode 100644 odb/qt/date-time/mysql/default-mapping.hxx create mode 100644 odb/qt/date-time/mysql/qdate-time-traits.hxx create mode 100644 odb/qt/date-time/mysql/qdate-traits.hxx create mode 100644 odb/qt/date-time/mysql/qtime-traits.hxx create mode 100644 odb/qt/date-time/sqlite/default-mapping.hxx create mode 100644 odb/qt/date-time/sqlite/qdate-time-traits.hxx create mode 100644 odb/qt/date-time/sqlite/qdate-traits.hxx create mode 100644 odb/qt/date-time/sqlite/qtime-traits.hxx delete mode 100644 odb/qt/dummy.cxx delete mode 100644 odb/qt/dummy.hxx delete mode 100644 odb/qt/mysql/default-mapping.hxx delete mode 100644 odb/qt/mysql/qbytearray-traits.hxx delete mode 100644 odb/qt/mysql/qdate-traits.hxx delete mode 100644 odb/qt/mysql/qdatetime-traits.hxx delete mode 100644 odb/qt/mysql/qstring-traits.hxx delete mode 100644 odb/qt/mysql/qtime-traits.hxx diff --git a/README b/README index 06ef2db..c19f0da 100644 --- a/README +++ b/README @@ -6,7 +6,7 @@ For more information see: http://www.codesynthesis.com/products/odb/ -This package contains the Boost Qt profile library. The Qt profile provides +This package contains the Qt profile library. The Qt profile provides support for persisting Qt smart pointers, containers, and value types with the ODB system. diff --git a/odb/qt.options b/odb/qt.options index bb51aab..76c25ec 100644 --- a/odb/qt.options +++ b/odb/qt.options @@ -3,10 +3,5 @@ # copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC # license : GNU GPL v2; see accompanying LICENSE file ---profile qt/version - ---odb-epilogue '#include ' ---hxx-prologue '#include ' ---hxx-prologue '#include ' ---hxx-prologue '#include ' ---hxx-prologue '#include ' \ No newline at end of file +--profile qt/basic +--profile qt/date-time diff --git a/odb/qt/basic-mysql.options b/odb/qt/basic-mysql.options new file mode 100644 index 0000000..adb3529 --- /dev/null +++ b/odb/qt/basic-mysql.options @@ -0,0 +1,11 @@ +# file : odb/qt/basic-mysql.options +# author : Constantin Michael +# copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +# license : GNU GPL v2; see accompanying LICENSE file + +--profile qt/version + +--odb-epilogue '#include ' + +--hxx-prologue '#include ' +--hxx-prologue '#include ' diff --git a/odb/qt/basic-sqlite.options b/odb/qt/basic-sqlite.options new file mode 100644 index 0000000..4a5a082 --- /dev/null +++ b/odb/qt/basic-sqlite.options @@ -0,0 +1,11 @@ +# file : odb/qt/basic-sqlite.options +# author : Constantin Michael +# copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +# license : GNU GPL v2; see accompanying LICENSE file + +--profile qt/version + +--odb-epilogue '#include ' + +--hxx-prologue '#include ' +--hxx-prologue '#include ' diff --git a/odb/qt/basic/mysql/default-mapping.hxx b/odb/qt/basic/mysql/default-mapping.hxx new file mode 100644 index 0000000..de73007 --- /dev/null +++ b/odb/qt/basic/mysql/default-mapping.hxx @@ -0,0 +1,24 @@ +// file : odb/qt/basic/mysql/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_MYSQL_DEFAULT_MAPPING_HXX +#define ODB_QT_BASIC_MYSQL_DEFAULT_MAPPING_HXX + +#include +#include + +// Map QString to MySQL VARCHAR (56) by default. +// +// @@ Temporary mapping until a solution for specifying primary key type +// has been implemented. +// +#pragma db value(QString) type("VARCHAR(56) NOT NULL") + +// Map QByteArray to MySQL BLOB by default. Allow NULL values by default as +// QByteArray provides a null representation. +// +#pragma db value(QByteArray) type("BLOB") + +#endif // ODB_QT_BASIC_MYSQL_DEFAULT_MAPPING_HXX diff --git a/odb/qt/basic/mysql/qbyte-array-traits.hxx b/odb/qt/basic/mysql/qbyte-array-traits.hxx new file mode 100644 index 0000000..f0239fd --- /dev/null +++ b/odb/qt/basic/mysql/qbyte-array-traits.hxx @@ -0,0 +1,67 @@ +// file : odb/qt/basic/mysql/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_MYSQL_QBYTE_ARRAY_TRAITS_HXX +#define ODB_QT_BASIC_MYSQL_QBYTE_ARRAY_TRAITS_HXX + +#include + +#include // std::memcpy +#include // std::size_t + +#include + +#include +#include + +namespace odb +{ + namespace mysql + { + template <> + class default_value_traits + { + 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 + v.replace (0, v.size (), b.data (), static_cast (n)); + } + + static void + set_image (details::buffer& b, + 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 ()); + + if (n > b.capacity ()) + b.capacity (n); + + std::memcpy (b.data (), v.data (), n); + } + } + }; + } +} + +#endif // ODB_QT_BASIC_MYSQL_QBYTE_ARRAY_TRAITS_HXX diff --git a/odb/qt/basic/mysql/qstring-traits.hxx b/odb/qt/basic/mysql/qstring-traits.hxx new file mode 100644 index 0000000..0ea8e86 --- /dev/null +++ b/odb/qt/basic/mysql/qstring-traits.hxx @@ -0,0 +1,94 @@ +// file : odb/qt/basic/mysql/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_MYSQL_QSTRING_TRAITS_HXX +#define ODB_QT_BASIC_MYSQL_QSTRING_TRAITS_HXX + +#include + +#include // std::memcpy +#include // std::size_t + +#include + +#include +#include + +namespace odb +{ + namespace mysql + { + class qstring_value_traits + { + public: + typedef QString value_type; + typedef QString query_type; + typedef details::buffer image_type; + + static void + set_value (QString& v, + const details::buffer& b, + std::size_t n, + bool is_null) + { + if (is_null) + v = QString (); + else + v = QString::fromUtf8 (b.data (), static_cast (n)); + } + + static void + set_image (details::buffer& b, + std::size_t& n, + bool& is_null, + const QString& v) + { + is_null = false; + + const QByteArray& a (v.toUtf8 ()); + n = static_cast (a.size ()); + + if (n > b.capacity ()) + b.capacity (n); + + std::memcpy (b.data (), a.data (), n); + } + }; + + template <> + struct default_value_traits< + QString, details::buffer, id_string>: qstring_value_traits + { + }; + + template <> + struct default_value_traits< + QString, details::buffer, id_decimal>: qstring_value_traits + { + }; + + template <> + struct default_value_traits< + QString, details::buffer, id_enum>: qstring_value_traits + { + }; + + template <> + struct default_value_traits< + QString, details::buffer, id_set>: qstring_value_traits + { + }; + + template <> + struct default_type_traits + { + static const database_type_id db_type_id = id_string; + }; + } +} + +#include + +#endif // ODB_QT_BASIC_MYSQL_QSTRING_TRAITS_HXX diff --git a/odb/qt/basic/sqlite/default-mapping.hxx b/odb/qt/basic/sqlite/default-mapping.hxx new file mode 100644 index 0000000..ea8108e --- /dev/null +++ b/odb/qt/basic/sqlite/default-mapping.hxx @@ -0,0 +1,22 @@ +// file : odb/qt/basic/sqlite/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_SQLITE_DEFAULT_MAPPING_HXX +#define ODB_QT_BASIC_SQLITE_DEFAULT_MAPPING_HXX + +#include +#include + +// Map QString to SQLite TEXT by default. Allow NULL values by default as +// QString provides a null representation. +// +#pragma db value(QString) type("TEXT") + +// Map QByteArray to SQLite TEXT by default. Allow NULL values by default as +// QByteArray provides a null representation. +// +#pragma db value(QByteArray) type("BLOB") + +#endif // ODB_QT_BASIC_SQLITE_DEFAULT_MAPPING_HXX diff --git a/odb/qt/basic/sqlite/qbyte-array-traits.hxx b/odb/qt/basic/sqlite/qbyte-array-traits.hxx new file mode 100644 index 0000000..5f30222 --- /dev/null +++ b/odb/qt/basic/sqlite/qbyte-array-traits.hxx @@ -0,0 +1,72 @@ +// file : odb/qt/basic/sqlite/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_SQLITE_QBYTE_ARRAY_TRAITS_HXX +#define ODB_QT_BASIC_SQLITE_QBYTE_ARRAY_TRAITS_HXX + +#include + +#include // std::memcpy +#include // std::size_t + +#include + +#include +#include + +namespace odb +{ + namespace sqlite + { + template <> + class default_value_traits + { + 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 + v.replace (0, v.size (), b.data (), static_cast (n)); + } + + static void + set_image (details::buffer& b, + 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 ()); + if (n > b.capacity ()) + b.capacity (n); + + std::memcpy (b.data (), v.data (), n); + } + } + }; + + template <> + class default_type_traits + { + static const database_type_id db_type_id = id_blob; + }; + } +} + +#endif // ODB_QT_BASIC_SQLITE_QBYTE_ARRAY_TRAITS_HXX diff --git a/odb/qt/basic/sqlite/qstring-traits.hxx b/odb/qt/basic/sqlite/qstring-traits.hxx new file mode 100644 index 0000000..31a9c1f --- /dev/null +++ b/odb/qt/basic/sqlite/qstring-traits.hxx @@ -0,0 +1,71 @@ +// file : odb/qt/basic/sqlite/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_SQLITE_QSTRING_TRAITS_HXX +#define ODB_QT_BASIC_SQLITE_QSTRING_TRAITS_HXX + +#include + +#include // std::memcpy +#include // std::size_t + +#include + +#include +#include + +namespace odb +{ + namespace sqlite + { + template <> + struct default_value_traits + { + public: + typedef QString value_type; + typedef QString query_type; + typedef details::buffer image_type; + + static void + set_value (QString& v, + const details::buffer& b, + std::size_t n, + bool is_null) + { + if (is_null) + v = QString (); + else + v = QString::fromUtf8 (b.data (), static_cast (n)); + } + + static void + set_image (details::buffer& b, + std::size_t& n, + bool& is_null, + const QString& v) + { + is_null = false; + + const QByteArray& a (v.toUtf8 ()); + n = static_cast (a.size ()); + + if (n > b.capacity ()) + b.capacity (n); + + std::memcpy (b.data (), a.data (), n); + } + }; + + template <> + struct default_type_traits + { + static const database_type_id db_type_id = id_text; + }; + } +} + +#include + +#endif // ODB_QT_BASIC_SQLITE_QSTRING_TRAITS_HXX diff --git a/odb/qt/config.h.in b/odb/qt/config.h.in deleted file mode 100644 index 4a1a204..0000000 --- a/odb/qt/config.h.in +++ /dev/null @@ -1,62 +0,0 @@ -/* odb/qt/config.h.in. Generated from configure.ac by autoheader. */ - -/* Define to 1 if you have the header file. */ -#undef HAVE_DLFCN_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_INTTYPES_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_MEMORY_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_STDINT_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_STDLIB_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_STRINGS_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_STRING_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_STAT_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_TYPES_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_UNISTD_H - -/* Define to the sub-directory in which libtool stores uninstalled libraries. - */ -#undef LT_OBJDIR - -/* Name of package */ -#undef PACKAGE - -/* Define to the address where bug reports for this package should be sent. */ -#undef PACKAGE_BUGREPORT - -/* Define to the full name of this package. */ -#undef PACKAGE_NAME - -/* Define to the full name and version of this package. */ -#undef PACKAGE_STRING - -/* Define to the one symbol short name of this package. */ -#undef PACKAGE_TARNAME - -/* Define to the home page for this package. */ -#undef PACKAGE_URL - -/* Define to the version of this package. */ -#undef PACKAGE_VERSION - -/* Define to 1 if you have the ANSI C header files. */ -#undef STDC_HEADERS - -/* Version number of package */ -#undef VERSION diff --git a/odb/qt/date-time-mysql.options b/odb/qt/date-time-mysql.options new file mode 100644 index 0000000..02bebf7 --- /dev/null +++ b/odb/qt/date-time-mysql.options @@ -0,0 +1,12 @@ +# file : odb/qt/date-time-mysql.options +# author : Constantin Michael +# copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +# license : GNU GPL v2; see accompanying LICENSE file + +--profile qt/version + +--odb-epilogue '#include ' + +--hxx-prologue '#include ' +--hxx-prologue '#include ' +--hxx-prologue '#include ' diff --git a/odb/qt/date-time-sqlite.options b/odb/qt/date-time-sqlite.options new file mode 100644 index 0000000..c500499 --- /dev/null +++ b/odb/qt/date-time-sqlite.options @@ -0,0 +1,12 @@ +# file : odb/qt/date-time-sqlite.options +# author : Constantin Michael +# copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +# license : GNU GPL v2; see accompanying LICENSE file + +--profile qt/version + +--odb-epilogue '#include ' + +--hxx-prologue '#include ' +--hxx-prologue '#include ' +--hxx-prologue '#include ' diff --git a/odb/qt/date-time/exceptions.cxx b/odb/qt/date-time/exceptions.cxx new file mode 100644 index 0000000..b2ccffe --- /dev/null +++ b/odb/qt/date-time/exceptions.cxx @@ -0,0 +1,21 @@ +// file : odb/qt/date-time/exceptions.cxx +// author : Constantin Michael +// copyright : Copyright (c) 2005-2011 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#include + +namespace odb +{ + namespace qt + { + namespace date_time + { + const char* value_out_of_range:: + what () const throw () + { + return "date/time value out of range"; + } + } + } +} diff --git a/odb/qt/date-time/exceptions.hxx b/odb/qt/date-time/exceptions.hxx new file mode 100644 index 0000000..445b110 --- /dev/null +++ b/odb/qt/date-time/exceptions.hxx @@ -0,0 +1,31 @@ +// file : odb/qt/date-time/exceptions.hxx +// author : Constantin Michael +// copyright : Copyright (c) 2005-2011 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_QT_DATE_TIME_EXCEPTIONS_HXX +#define ODB_QT_DATE_TIME_EXCEPTIONS_HXX + +#include + +#include +#include + +namespace odb +{ + namespace qt + { + namespace date_time + { + struct LIBODB_QT_EXPORT value_out_of_range: exception + { + virtual const char* + what () const throw (); + }; + } + } +} + +#include + +#endif // ODB_QT_DATE_TIME_EXCEPTIONS_HXX diff --git a/odb/qt/date-time/mysql/default-mapping.hxx b/odb/qt/date-time/mysql/default-mapping.hxx new file mode 100644 index 0000000..fa0b823 --- /dev/null +++ b/odb/qt/date-time/mysql/default-mapping.hxx @@ -0,0 +1,28 @@ +// file : odb/qt/date-time/mysql/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_MYSQL_DEFAULT_MAPPING_HXX +#define ODB_QT_DATE_TIME_MYSQL_DEFAULT_MAPPING_HXX + +#include +#include +#include + +// Map QDate to MySQL DATE by default. QDate provides a null +// representation so allow NULL values by default. +// +#pragma db value(QDate) type("DATE") + +// Map QTime to MySQL TIME by default. QTime provides a null +// representation so allow NULL values by default. +// +#pragma db value(QTime) type("TIME") + +// Map QDateTime to MySQL DATETIME by default. QDateTime provides a null +// representation so allow NULL values by default. +// +#pragma db value(QDateTime) type("DATETIME") + +#endif // ODB_QT_DATE_TIME_MYSQL_DEFAULT_MAPPING_HXX diff --git a/odb/qt/date-time/mysql/qdate-time-traits.hxx b/odb/qt/date-time/mysql/qdate-time-traits.hxx new file mode 100644 index 0000000..9d212a3 --- /dev/null +++ b/odb/qt/date-time/mysql/qdate-time-traits.hxx @@ -0,0 +1,127 @@ +// file : odb/qt/date-time/mysql/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_MYSQL_QDATETIME_TRAITS_HXX +#define ODB_QT_DATE_TIME_MYSQL_QDATETIME_TRAITS_HXX + +#include + +#include + +#include + +namespace odb +{ + namespace mysql + { + template <> + class default_value_traits + { + 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) + // Default constructor creates a null QDateTime. + // + v = QDateTime (); + else + v = QDateTime (QDate (static_cast (i.year), + static_cast (i.month), + static_cast (i.day)), + QTime (static_cast (i.hour), + static_cast (i.minute), + static_cast (i.second))); + } + + static void + set_image (MYSQL_TIME& i, bool& is_null, const QDateTime& v) + { + if (v.isNull ()) + is_null = true; + else + { + if ((v < QDateTime (QDate (1000, 1, 1))) || + (v >= QDateTime (QDate (10000, 1, 1)))) + throw odb::qt::date_time::value_out_of_range (); + + is_null = false; + + const QDate& d (v.date ()); + i.year = static_cast (d.year ()); + i.month = static_cast (d.month ()); + i.day = static_cast (d.day ()); + + const QTime& t (v.time ()); + i.hour = static_cast (t.hour ()); + i.minute = static_cast (t.minute ()); + i.second = static_cast (t.second ()); + } + } + }; + + template <> + class default_value_traits + { + 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) + // Default constructor creates a null QDateTime. + // + v = QDateTime (); + else + v = QDateTime (QDate (static_cast (i.year), + static_cast (i.month), + static_cast (i.day)), + QTime (static_cast (i.hour), + static_cast (i.minute), + static_cast (i.second))); + } + + static void + set_image (MYSQL_TIME& i, bool& is_null, const QDateTime& v) + { + if (v.isNull ()) + is_null = true; + else + { + if ((v <= QDateTime (QDate (1970, 1, 1))) || + (v > QDateTime (QDate (2038, 1, 19), QTime (3, 14, 7)))) + throw odb::qt::date_time::value_out_of_range (); + + is_null = false; + + const QDate& d (v.date ()); + i.year = static_cast (d.year ()); + i.month = static_cast (d.month ()); + i.day = static_cast (d.day ()); + + const QTime& t (v.time ()); + i.hour = static_cast (t.hour ()); + i.minute = static_cast (t.minute ()); + i.second = static_cast (t.second ()); + } + } + }; + + template <> + class default_type_traits + { + static const database_type_id db_type_od = id_datetime; + }; + } +} + +#endif // ODB_QT_DATE_TIME_MYSQL_QDATETIME_TRAITS_HXX diff --git a/odb/qt/date-time/mysql/qdate-traits.hxx b/odb/qt/date-time/mysql/qdate-traits.hxx new file mode 100644 index 0000000..1034cbc --- /dev/null +++ b/odb/qt/date-time/mysql/qdate-traits.hxx @@ -0,0 +1,68 @@ +// file : odb/qt/date-time/mysql/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_MYSQL_QDATE_TRAITS_HXX +#define ODB_QT_DATE_TIME_MYSQL_QDATE_TRAITS_HXX + +#include + +#include + +#include +#include + +namespace odb +{ + namespace mysql + { + template <> + class default_value_traits + { + 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) + // 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 + v.setDate (static_cast (i.year), + static_cast (i.month), + static_cast (i.day)); + } + + static void + set_image (MYSQL_TIME& i, bool& is_null, const QDate& v) + { + if (v.isNull ()) + is_null = true; + else if ((v < QDate (1000, 1, 1)) || (v > QDate (9999, 12, 31))) + throw odb::qt::date_time::value_out_of_range (); + else + { + is_null = false; + + i.year = static_cast (v.year ()); + i.month = static_cast (v.month ()); + i.day = static_cast (v.day ()); + } + } + }; + + template <> + class default_type_traits + { + static const database_type_id db_type_id = id_date; + }; + } +} + +#endif // ODB_QT_DATE_TIME_MYSQL_QDATE_TRAITS_HXX diff --git a/odb/qt/date-time/mysql/qtime-traits.hxx b/odb/qt/date-time/mysql/qtime-traits.hxx new file mode 100644 index 0000000..69cd49c --- /dev/null +++ b/odb/qt/date-time/mysql/qtime-traits.hxx @@ -0,0 +1,69 @@ +// file : odb/qt/date-time/mysql/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_MYSQL_QTIME_TRAITS_HXX +#define ODB_QT_DATE_TIME_MYSQL_QTIME_TRAITS_HXX + +#include + +#include + +#include + +namespace odb +{ + namespace mysql + { + template <> + class default_value_traits + { + 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) + // 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 + v.setHMS (static_cast (i.hour), + static_cast (i.minute), + static_cast (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.neg = false; + i.day = 0; + + i.hour = static_cast (v.hour ()); + i.minute = static_cast (v.minute ()); + i.second = static_cast (v.second ()); + } + } + }; + + template <> + class default_type_traits + { + static const database_type_id db_type_id = id_time; + }; + } +} + +#endif // ODB_QT_DATE_TIME_MYSQL_QTIME_TRAITS_HXX diff --git a/odb/qt/date-time/sqlite/default-mapping.hxx b/odb/qt/date-time/sqlite/default-mapping.hxx new file mode 100644 index 0000000..82321af --- /dev/null +++ b/odb/qt/date-time/sqlite/default-mapping.hxx @@ -0,0 +1,28 @@ +// file : odb/qt/date-time/sqlite/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_SQLITE_DEFAULT_MAPPING_HXX +#define ODB_QT_DATE_TIME_SQLITE_DEFAULT_MAPPING_HXX + +#include +#include +#include + +// Map QDate to SQLite TEXT by default. QDate provides a null representation +// so allow NULL values by default. +// +#pragma db value(QDate) type("TEXT") + +// Map QTime to SQLite TEXT by default. QTime provides a null representation +// so allow NULL values by default. +// +#pragma db value(QTime) type("TEXT") + +// Map QDateTime to SQLite TEXT by default. QDateTime provides a null +// representation so allow NULL values by default. +// +#pragma db value(QDateTime) type("TEXT") + +#endif // ODB_QT_DATE_TIME_SQLITE_DEFAULT_MAPPING_HXX diff --git a/odb/qt/date-time/sqlite/qdate-time-traits.hxx b/odb/qt/date-time/sqlite/qdate-time-traits.hxx new file mode 100644 index 0000000..85c4c1a --- /dev/null +++ b/odb/qt/date-time/sqlite/qdate-time-traits.hxx @@ -0,0 +1,123 @@ +// file : odb/qt/date-time/sqlite/qdatetime-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_SQLITE_QDATETIME_TRAITS_HXX +#define ODB_QT_DATE_TIME_SQLITE_QDATETIME_TRAITS_HXX + +#include + +#include +#include // std::size_t +#include // std::memcpy + +#include + +#include +#include +#include + +namespace odb +{ + namespace sqlite + { + template <> + class default_value_traits + { + public: + typedef QDateTime value_type; + typedef QDateTime query_type; + typedef details::buffer image_type; + + static void + set_value (QDateTime& v, + const details::buffer& i, + std::size_t n, + bool is_null) + { + if (is_null) + // Default constructor creates a null QDateTime. + // + v = QDateTime (); + else + v = QDateTime::fromString ( + QString::fromAscii (i.data (), static_cast (n)), + "yyyy-MM-ddTHH:mm:ss.zzz"); + } + + static void + set_image (details::buffer& i, + std::size_t& n, + bool& is_null, + const QDateTime& v) + { + if (v.isNull ()) + is_null = true; + else + { + is_null = false; + + std::string s ( + v.toString ("yyyy-MM-ddTHH:mm:ss.zzz").toStdString ()); + + n = s.size (); + if (n > i.capacity ()) + i.capacity (n); + + std::memcpy (i.data (), s.data (), n); + } + } + }; + + // Implementation of mapping between QDateTime and SQLite INTEGER. + // The integer value represents UNIX time. + // + template <> + class default_value_traits + { + public: + typedef QDateTime value_type; + typedef QDateTime query_type; + typedef long long image_type; + + static void + set_value (QDateTime& v, long long i, bool is_null) + { + if (is_null) + // Default constructor creates a null QDateTime. + // + v = QDateTime (); + else + { + v.setTimeSpec (Qt::UTC); + v.setTime_t (static_cast (i)); + } + } + + static void + set_image (long long& i, bool& is_null, const QDateTime& v) + { + if (v.isNull ()) + is_null = true; + else if (v < QDateTime (QDate (1970, 1, 1), + QTime (0, 0, 0), + Qt::UTC)) + throw odb::qt::date_time::value_out_of_range (); + else + { + is_null = false; + i = static_cast (v.toTime_t ()); + } + } + }; + + template <> + class default_type_traits + { + static const database_type_id db_type_id = id_text; + }; + } +} + +#endif // ODB_QT_DATE_TIME_SQLITE_QDATETIME_TRAITS_HXX diff --git a/odb/qt/date-time/sqlite/qdate-traits.hxx b/odb/qt/date-time/sqlite/qdate-traits.hxx new file mode 100644 index 0000000..d8df614 --- /dev/null +++ b/odb/qt/date-time/sqlite/qdate-traits.hxx @@ -0,0 +1,126 @@ +// file : odb/qt/date-time/sqlite/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_SQLITE_QDATE_TRAITS_HXX +#define ODB_QT_DATE_TIME_SQLITE_QDATE_TRAITS_HXX + +#include + +#include +#include // std::size_t +#include // std::memcpy + +#include + +#include +#include +#include + +namespace odb +{ + namespace sqlite + { + template <> + class default_value_traits + { + public: + typedef QDate value_type; + typedef QDate query_type; + typedef details::buffer image_type; + + static void + set_value (QDate& v, + const details::buffer& i, + std::size_t n, + 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 + v = QDate::fromString ( + QString::fromAscii (i.data (), static_cast (n)), + "yyyy-MM-dd"); + } + + static void + set_image (details::buffer& i, + std::size_t& n, + bool& is_null, + const QDate& v) + { + if (v.isNull ()) + is_null = true; + else + { + is_null = false; + + std::string s (v.toString ("yyyy-MM-dd").toStdString ()); + + n = s.size (); + if (n > i.capacity ()) + i.capacity (n); + + std::memcpy (i.data (), s.data (), n); + } + } + }; + + // Implementation of the mapping between QDate and SQLite INTEGER. The + // integer value represents UNIX time. + // + template <> + class default_value_traits + { + public: + typedef QDate value_type; + typedef QDate query_type; + typedef long long image_type; + + static void + set_value (QDate& v, long long i, 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 + { + QDateTime dt; + dt.setTimeSpec (Qt::UTC); + dt.setTime_t(static_cast (i)); + + v = dt.date (); + } + } + + static void + set_image (long long& i, bool& is_null, const QDate& v) + { + if (v.isNull ()) + is_null = true; + else if (v < QDate (1970, 1, 1)) + throw odb::qt::date_time::value_out_of_range (); + else + { + is_null = false; + i = static_cast ( + QDateTime (v, QTime (0, 0, 0), Qt::UTC).toTime_t ()); + } + } + }; + + template <> + class default_type_traits + { + static const database_type_id db_type_id = id_text; + }; + } +} + +#endif // ODB_QT_DATE_TIME_SQLITE_QDATE_TRAITS_HXX diff --git a/odb/qt/date-time/sqlite/qtime-traits.hxx b/odb/qt/date-time/sqlite/qtime-traits.hxx new file mode 100644 index 0000000..84721ee --- /dev/null +++ b/odb/qt/date-time/sqlite/qtime-traits.hxx @@ -0,0 +1,118 @@ +// file : odb/qt/date-time/sqlite/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_SQLITE_QTIME_TRAITS_HXX +#define ODB_QT_DATE_TIME_SQLITE_QTIME_TRAITS_HXX + +#include + +#include +#include // std::size_t +#include // std::memcpy + +#include + +#include +#include + +namespace odb +{ + namespace sqlite + { + template <> + class default_value_traits + { + public: + typedef QTime value_type; + typedef QTime query_type; + typedef details::buffer image_type; + + static void + set_value (QTime& v, + const details::buffer& i, + std::size_t n, + 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 + v = QTime::fromString ( + QString::fromAscii (i.data (), static_cast (n)), + "HH:mm:ss.zzz"); + } + + static void + set_image (details::buffer& i, + std::size_t& n, + bool& is_null, + const QTime& v) + { + if (v.isNull ()) + is_null = true; + else + { + is_null = false; + + std::string s (v.toString ("HH:mm:ss.zzz").toStdString ()); + + n = s.size (); + if (n > i.capacity ()) + i.capacity (n); + + std::memcpy (i.data (), s.data (), n); + } + } + }; + + // Implementation of mapping between QTime and SQLite INTEGER. The + // integer value represents seconds since midnight. + // + template <> + class default_value_traits + { + public: + typedef QTime value_type; + typedef QTime query_type; + typedef long long image_type; + + static void + set_value (QTime& v, long long 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 + v = QTime (0, 0, 0).addSecs (static_cast (i)); + } + + static void + set_image (long long& i, bool& is_null, const QTime& v) + { + if (v.isNull ()) + is_null = true; + else + { + is_null = false; + i = static_cast (QTime (0, 0, 0).secsTo (v)); + } + } + }; + + template <> + class default_type_traits + { + static const database_type_id db_type_id = id_text; + }; + } +} + +#endif // ODB_QT_DATE_TIME_SQLITE_QTIME_TRAITS_HXX diff --git a/odb/qt/dummy.cxx b/odb/qt/dummy.cxx deleted file mode 100644 index 81468bc..0000000 --- a/odb/qt/dummy.cxx +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include - -namespace odb -{ - namespace qt - { - QString dummy () - { - QString s ("Hello, Qt!"); - return s; - } - } -} diff --git a/odb/qt/dummy.hxx b/odb/qt/dummy.hxx deleted file mode 100644 index e35625a..0000000 --- a/odb/qt/dummy.hxx +++ /dev/null @@ -1,12 +0,0 @@ -// Force compilation and creation of libodb-qt library for now. -// -#include -#include - -namespace odb -{ - namespace qt - { - LIBODB_QT_EXPORT QString dummy (); - } -} diff --git a/odb/qt/exception.hxx b/odb/qt/exception.hxx index 6bf0699..0e09977 100644 --- a/odb/qt/exception.hxx +++ b/odb/qt/exception.hxx @@ -1,5 +1,5 @@ // file : odb/qt/exception.hxx -// author : Boris Kolpackov +// author : Constantin Michael // copyright : Copyright (c) 2005-2011 Code Synthesis Tools CC // license : GNU GPL v2; see accompanying LICENSE file diff --git a/odb/qt/libodb-qt-vc10.vcxproj b/odb/qt/libodb-qt-vc10.vcxproj index fb50334..6ea6610 100644 --- a/odb/qt/libodb-qt-vc10.vcxproj +++ b/odb/qt/libodb-qt-vc10.vcxproj @@ -88,7 +88,7 @@ Level3 Disabled - WIN32;_DEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBODB_QT_DYNAMIC_LIB;%(PreprocessorDefinitions) ..\.. 4355;4800;4290;4251;%(DisableSpecificWarnings) @@ -106,7 +106,7 @@ Level3 Disabled - WIN32;_DEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBODB_QT_DYNAMIC_LIB;%(PreprocessorDefinitions) ..\.. 4355;4800;4290;4251;%(DisableSpecificWarnings) @@ -126,7 +126,7 @@ MaxSpeed true true - WIN32;NDEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + WIN32;NDEBUG;_WINDOWS;_USRDLL;LIBODB_QT_DYNAMIC_LIB;%(PreprocessorDefinitions) ..\.. 4355;4800;4290;4251;%(DisableSpecificWarnings) @@ -148,7 +148,7 @@ MaxSpeed true true - WIN32;NDEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + WIN32;NDEBUG;_WINDOWS;_USRDLL;LIBODB_QT_DYNAMIC_LIB;%(PreprocessorDefinitions) ..\.. 4355;4800;4290;4251;%(DisableSpecificWarnings) diff --git a/odb/qt/libodb-qt-vc9.vcproj b/odb/qt/libodb-qt-vc9.vcproj index 471538a..328e6b1 100644 --- a/odb/qt/libodb-qt-vc9.vcproj +++ b/odb/qt/libodb-qt-vc9.vcproj @@ -46,7 +46,7 @@ AdditionalOptions="/wd4355 /wd4800 /wd4290" Optimization="0" AdditionalIncludeDirectories="..\.." - PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL" + PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBODB_QT_DYNAMIC_LIB;" MinimalRebuild="true" BasicRuntimeChecks="3" RuntimeLibrary="3" @@ -124,7 +124,7 @@ AdditionalOptions="/wd4355 /wd4800 /wd4290" Optimization="0" AdditionalIncludeDirectories="..\.." - PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL" + PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBODB_QT_DYNAMIC_LIB;" MinimalRebuild="true" BasicRuntimeChecks="3" RuntimeLibrary="3" @@ -203,7 +203,7 @@ Optimization="2" EnableIntrinsicFunctions="true" AdditionalIncludeDirectories="..\.." - PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL" + PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;LIBODB_QT_DYNAMIC_LIB;" RuntimeLibrary="2" EnableFunctionLevelLinking="true" UsePrecompiledHeader="0" @@ -284,7 +284,7 @@ Optimization="2" EnableIntrinsicFunctions="true" AdditionalIncludeDirectories="..\.." - PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL" + PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;LIBODB_QT_DYNAMIC_LIB;" RuntimeLibrary="2" EnableFunctionLevelLinking="true" UsePrecompiledHeader="0" diff --git a/odb/qt/makefile b/odb/qt/makefile index 756edd0..b806dac 100644 --- a/odb/qt/makefile +++ b/odb/qt/makefile @@ -5,7 +5,7 @@ include $(dir $(lastword $(MAKEFILE_LIST)))../../build/bootstrap.make -cxx := dummy.cxx +cxx := date-time/exceptions.cxx cxx_tun := $(cxx) cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o)) diff --git a/odb/qt/mysql/default-mapping.hxx b/odb/qt/mysql/default-mapping.hxx deleted file mode 100644 index 6a948c4..0000000 --- a/odb/qt/mysql/default-mapping.hxx +++ /dev/null @@ -1,30 +0,0 @@ -// file : qt/mysql/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_MYSQL_DEFAULT_MAPPING_HXX -#define ODB_QT_MYSQL_DEFAULT_MAPPING_HXX - -#include -#include -#include -#include - -// 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 deleted file mode 100644 index d94bf44..0000000 --- a/odb/qt/mysql/qbytearray-traits.hxx +++ /dev/null @@ -1,71 +0,0 @@ -// file : odb/qt/mysql/qbytearray-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_MYSQL_QBYTEARRAY_TRAITS_HXX -#define ODB_QT_MYSQL_QBYTEARRAY_TRAITS_HXX - -#include - -#include // std::memcpy -#include // std::size_t - -#include - -#include -#include - -namespace odb -{ - namespace mysql - { - template <> - class default_value_traits - { - 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 deleted file mode 100644 index 168e6f9..0000000 --- a/odb/qt/mysql/qdate-traits.hxx +++ /dev/null @@ -1,55 +0,0 @@ -// file : odb/qt/mysql/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_MYSQL_QDATE_TRAITS_HXX -#define ODB_QT_MYSQL_QDATE_TRAITS_HXX - -#include - -#include - -#include - -namespace odb -{ - namespace mysql - { - template <> - class default_value_traits - { - 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 deleted file mode 100644 index 75cb05e..0000000 --- a/odb/qt/mysql/qdatetime-traits.hxx +++ /dev/null @@ -1,109 +0,0 @@ -// file : odb/qt/mysql/qdatetime-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_MYSQL_QDATETIME_TRAITS_HXX -#define ODB_QT_MYSQL_QDATETIME_TRAITS_HXX - -#include - -#include - -#include - -namespace odb -{ - namespace mysql - { - template <> - class default_value_traits - { - 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.isNull ()) - 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 (); - } - } - }; - - template <> - class default_value_traits - { - 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.isNull ()) - 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 deleted file mode 100644 index facb569..0000000 --- a/odb/qt/mysql/qstring-traits.hxx +++ /dev/null @@ -1,95 +0,0 @@ -// file : odb/qt/mysql/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_MYSQL_QSTRING_TRAITS_HXX -#define ODB_QT_MYSQL_QSTRING_TRAITS_HXX - -#include - -#include // std::memcpy -#include // std::size_t - -#include - -#include -#include - -namespace odb -{ - namespace mysql - { - class qstring_value_traits - { - public: - typedef QString value_type; - typedef QString query_type; - typedef details::buffer image_type; - - static void - set_value (QString& v, - const details::buffer& b, - std::size_t n, - bool is_null) - { - if (!is_null) - v = QString::fromUtf8 (b.data (), n); - else - v.clear (); - } - - static void - set_image (details::buffer& b, - std::size_t& n, - bool& is_null, - const QString& v) - { - is_null = false; - - const QByteArray& a (v.toUtf8 ()); - n = a.size (); - - if (n > b.capacity ()) - b.capacity (n); - - if (n != 0) - std::memcpy (b.data (), a.data (), n); - } - }; - - template <> - struct default_value_traits< - QString, details::buffer, id_string>: qstring_value_traits - { - }; - - template <> - struct default_value_traits< - QString, details::buffer, id_decimal>: qstring_value_traits - { - }; - - template <> - struct default_value_traits< - QString, details::buffer, id_enum>: qstring_value_traits - { - }; - - template <> - struct default_value_traits< - QString, details::buffer, id_set>: qstring_value_traits - { - }; - - template <> - struct default_type_traits - { - static const database_type_id db_type_id = id_string; - }; - } -} - -#include - -#endif // ODB_QT_MYSQL_QSTRING_TRAITS_HXX diff --git a/odb/qt/mysql/qtime-traits.hxx b/odb/qt/mysql/qtime-traits.hxx deleted file mode 100644 index 9789114..0000000 --- a/odb/qt/mysql/qtime-traits.hxx +++ /dev/null @@ -1,55 +0,0 @@ -// file : odb/qt/mysql/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_MYSQL_QTIME_TRAITS_HXX -#define ODB_QT_MYSQL_QTIME_TRAITS_HXX - -#include - -#include - -#include - -namespace odb -{ - namespace mysql - { - template <> - class default_value_traits - { - 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 diff --git a/odb/qt/version.hxx b/odb/qt/version.hxx index 88ca1a1..9f97768 100644 --- a/odb/qt/version.hxx +++ b/odb/qt/version.hxx @@ -29,15 +29,15 @@ // Check that we have compatible ODB version. // -#if ODB_VERSION != 10200 +#if ODB_VERSION != 10251 # error incompatible odb interface version detected #endif // libodb-qt version: odb interface version plus the bugfix // version. // -#define LIBODB_QT_VERSION 1020000 -#define LIBODB_QT_VERSION_STR "1.2.0" +#define LIBODB_QT_VERSION 1029951 +#define LIBODB_QT_VERSION_STR "1.3.0.b1" #include diff --git a/odb/qt/version.options b/odb/qt/version.options index cdecaf3..13285bc 100644 --- a/odb/qt/version.options +++ b/odb/qt/version.options @@ -8,6 +8,6 @@ # --hxx-prologue '#include ' ---hxx-prologue '#if LIBODB_QT_VERSION != 1020000 // 1.2.0' +--hxx-prologue '#if LIBODB_QT_VERSION != 1029951 // 1.3.0.b1' --hxx-prologue '# error ODB and C++ compilers see different libodb-qt versions' --hxx-prologue '#endif' diff --git a/version b/version index 26aaba0..c92d778 100644 --- a/version +++ b/version @@ -1 +1 @@ -1.2.0 +1.3.0.b1 -- cgit v1.1