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/basic/oracle/qbyte-array-traits.hxx | 167 +++++++++++++++++++++ 1 file changed, 167 insertions(+) create mode 100644 libodb-qt/odb/qt/basic/oracle/qbyte-array-traits.hxx (limited to 'libodb-qt/odb/qt/basic/oracle/qbyte-array-traits.hxx') diff --git a/libodb-qt/odb/qt/basic/oracle/qbyte-array-traits.hxx b/libodb-qt/odb/qt/basic/oracle/qbyte-array-traits.hxx new file mode 100644 index 0000000..6979cc9 --- /dev/null +++ b/libodb-qt/odb/qt/basic/oracle/qbyte-array-traits.hxx @@ -0,0 +1,167 @@ +// file : odb/qt/basic/oracle/qbyte-array-traits.hxx +// 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 ()); + + if (n > c) + n = c; + + std::memcpy (b, v.constData (), n); + } + } + }; + + template <> + struct default_value_traits + { + typedef QByteArray value_type; + typedef QByteArray query_type; + typedef lob_callback image_type; + + static void + set_value (QByteArray& v, + result_callback_type& cb, + void*& context, + bool is_null) + { + if (is_null) + v = QByteArray (); + else + { + cb = &result_callback; + context = &v; + } + } + + static void + set_image (param_callback_type& cb, + const void*& context, + bool& is_null, + const QByteArray& v) + { + if (v.isNull ()) + is_null = true; + else + { + is_null = false; + cb = ¶m_callback; + context = &v; + } + } + + static bool + result_callback (void* context, + ub4*, + void* b, + ub4 s, + chunk_position p) + { + QByteArray& v (*static_cast (context)); + + switch (p) + { + case chunk_one: + case chunk_first: + { + v.clear (); + + // Falling through. + } + case chunk_next: + case chunk_last: + { + v.append (static_cast (b), static_cast (s)); + break; + } + } + + return true; + } + + static bool + param_callback (const void* context, + ub4*, + const void** b, + ub4* s, + chunk_position* p, + void*, + ub4) + { + const QByteArray& v (*static_cast (context)); + + *p = chunk_one; + *s = static_cast (v.size ()); + *b = v.constData (); + + return true; + } + }; + + template <> + struct default_type_traits + { + // Allow use of QByteArray in query expressions by default by specifying + // the default type id as RAW. + // + static const database_type_id db_type_id = id_raw; + }; + } +} + +#include + +#endif // ODB_QT_BASIC_ORACLE_QBYTE_ARRAY_TRAITS_HXX -- cgit v1.1