From 5f1cd97b9727fe10df79e1eb316ff493d9dfc2a9 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 1 Feb 2024 20:50:43 +0300 Subject: Turn libodb-qt repository into package for muti-package repository --- .../odb/qt/date-time/pgsql/qdate-time-traits.hxx | 70 ++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 libodb-qt/odb/qt/date-time/pgsql/qdate-time-traits.hxx (limited to 'libodb-qt/odb/qt/date-time/pgsql/qdate-time-traits.hxx') diff --git a/libodb-qt/odb/qt/date-time/pgsql/qdate-time-traits.hxx b/libodb-qt/odb/qt/date-time/pgsql/qdate-time-traits.hxx new file mode 100644 index 0000000..a9fe757 --- /dev/null +++ b/libodb-qt/odb/qt/date-time/pgsql/qdate-time-traits.hxx @@ -0,0 +1,70 @@ +// file : odb/qt/date-time/pgsql/qdatetime-traits.hxx +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_QT_DATE_TIME_PGSQL_QDATETIME_TRAITS_HXX +#define ODB_QT_DATE_TIME_PGSQL_QDATETIME_TRAITS_HXX + +#include + +#include + +#include + +namespace odb +{ + namespace pgsql + { + // Implementation of mapping between QDateTime and PostgreSQL TIMESTAMP. + // TIMESTAMP values are stored as micro-seconds since the PostgreSQL + // epoch 2000-01-01. + // + template <> + struct default_value_traits + { + typedef details::endian_traits endian_traits; + + 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 + { + const QDateTime pg_epoch (QDate (2000, 1, 1), QTime (0, 0, 0)); + v = pg_epoch.addMSecs ( + static_cast (endian_traits::ntoh (i) / 1000LL)); + } + } + + static void + set_image (long long& i, bool& is_null, const QDateTime& v) + { + if (v.isNull ()) + is_null = true; + else + { + is_null = false; + const QDateTime pg_epoch (QDate (2000, 1, 1), QTime (0, 0, 0)); + i = endian_traits::hton ( + static_cast (pg_epoch.msecsTo (v)) * 1000LL); + } + } + }; + + template <> + struct default_type_traits + { + static const database_type_id db_type_id = id_timestamp; + }; + } +} + +#include + +#endif // ODB_QT_DATE_TIME_PGSQL_QDATETIME_TRAITS_HXX -- cgit v1.1