summaryrefslogtreecommitdiff
path: root/libodb-qt/odb/qt/basic/oracle
diff options
context:
space:
mode:
Diffstat (limited to 'libodb-qt/odb/qt/basic/oracle')
-rw-r--r--libodb-qt/odb/qt/basic/oracle/default-mapping.hxx27
-rw-r--r--libodb-qt/odb/qt/basic/oracle/qbyte-array-traits.hxx167
-rw-r--r--libodb-qt/odb/qt/basic/oracle/qstring-traits.hxx206
-rw-r--r--libodb-qt/odb/qt/basic/oracle/quuid-traits.hxx70
4 files changed, 470 insertions, 0 deletions
diff --git a/libodb-qt/odb/qt/basic/oracle/default-mapping.hxx b/libodb-qt/odb/qt/basic/oracle/default-mapping.hxx
new file mode 100644
index 0000000..8d72206
--- /dev/null
+++ b/libodb-qt/odb/qt/basic/oracle/default-mapping.hxx
@@ -0,0 +1,27 @@
+// file : odb/qt/basic/oracle/default-mapping.hxx
+// 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>
+#include <QtCore/QUuid>
+
+// Map QString to Oracle VARCHAR2 by default. Allow NULL values by default as
+// QString provides a null representation.
+//
+#pragma db value(QString) type("VARCHAR2(512)") null
+
+// Map QByteArray to Oracle BLOB by default. Allow NULL values by default as
+// QByteArray provides a null representation.
+//
+#pragma db value(QByteArray) type("BLOB") null
+
+// By default map QUuid to Oracle RAW(16) and use NULL to represent null
+// UUIDs. If NULL is disabled (e.g., at the member level), then we store
+// the null UUID (i.e., all bytes are zero).
+//
+#pragma db value(QUuid) type("RAW(16)") null
+
+#endif // ODB_QT_BASIC_ORACLE_DEFAULT_MAPPING_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 <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 ());
+
+ if (n > c)
+ n = c;
+
+ std::memcpy (b, v.constData (), n);
+ }
+ }
+ };
+
+ template <>
+ struct default_value_traits<QByteArray, id_blob>
+ {
+ 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 = &param_callback;
+ context = &v;
+ }
+ }
+
+ static bool
+ result_callback (void* context,
+ ub4*,
+ void* b,
+ ub4 s,
+ chunk_position p)
+ {
+ QByteArray& v (*static_cast<QByteArray*> (context));
+
+ switch (p)
+ {
+ case chunk_one:
+ case chunk_first:
+ {
+ v.clear ();
+
+ // Falling through.
+ }
+ case chunk_next:
+ case chunk_last:
+ {
+ v.append (static_cast<char*> (b), static_cast<int> (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<const QByteArray*> (context));
+
+ *p = chunk_one;
+ *s = static_cast<ub4> (v.size ());
+ *b = v.constData ();
+
+ return true;
+ }
+ };
+
+ template <>
+ struct default_type_traits<QByteArray>
+ {
+ // 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 <odb/post.hxx>
+
+#endif // ODB_QT_BASIC_ORACLE_QBYTE_ARRAY_TRAITS_HXX
diff --git a/libodb-qt/odb/qt/basic/oracle/qstring-traits.hxx b/libodb-qt/odb/qt/basic/oracle/qstring-traits.hxx
new file mode 100644
index 0000000..418d30e
--- /dev/null
+++ b/libodb-qt/odb/qt/basic/oracle/qstring-traits.hxx
@@ -0,0 +1,206 @@
+// file : odb/qt/basic/oracle/qstring-traits.hxx
+// 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
+ {
+ struct qstring_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<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 ());
+
+ if (n > c)
+ n = c;
+
+ std::memcpy (b, a.constData (), n);
+ }
+ }
+ };
+
+ template <>
+ struct default_value_traits <QString, id_string>: qstring_value_traits
+ {
+ };
+
+ template <>
+ struct default_value_traits <QString, id_nstring>: qstring_value_traits
+ {
+ };
+
+ class qstring_lob_value_traits
+ {
+ public:
+ typedef QString value_type;
+ typedef QString query_type;
+ typedef lob_callback image_type;
+
+ static void
+ set_value (QString& v,
+ result_callback_type& cb,
+ void*& context,
+ bool is_null)
+ {
+ if (is_null)
+ v = QString ();
+ else
+ {
+ cb = &result_callback;
+ context = &v;
+ }
+ }
+
+ static void
+ set_image (param_callback_type& cb,
+ const void*& context,
+ bool& is_null,
+ const QString& v)
+ {
+ if (v.isNull ())
+ is_null = true;
+ else
+ {
+ is_null = false;
+ cb = &param_callback;
+ context = &v;
+ }
+ }
+
+ static bool
+ result_callback (void* context,
+ ub4*,
+ void* b,
+ ub4 s,
+ chunk_position p)
+ {
+ QString& v (*static_cast<QString*> (context));
+
+ switch (p)
+ {
+ case chunk_one:
+ case chunk_first:
+ {
+ v.clear ();
+
+ // Falling through.
+ }
+ case chunk_next:
+ case chunk_last:
+ {
+ v += QString::fromUtf8(static_cast<char*> (b),
+ static_cast<int> (s));
+ break;
+ }
+ }
+
+ return true;
+ }
+
+ static bool
+ param_callback (const void* context,
+ ub4* position_context,
+ const void** b,
+ ub4* s,
+ chunk_position* p,
+ void* temp_buffer,
+ ub4 capacity)
+ {
+ const QByteArray& v (static_cast<const QString*> (context)->toUtf8 ());
+
+ *s = static_cast<ub4> (v.size ());
+
+ if (*position_context == 0)
+ {
+ if (*s <= capacity)
+ *p = chunk_one;
+ else
+ {
+ *s = capacity;
+ *p = chunk_first;
+ }
+ }
+ else
+ {
+ *s -= *position_context;
+
+ if (*s <= capacity)
+ *p = chunk_last;
+ else
+ {
+ *s = capacity;
+ *p = chunk_next;
+ }
+ }
+
+ std::memcpy (temp_buffer, v.constData () + *position_context, *s);
+ *b = temp_buffer;
+ *position_context += *s;
+
+ return true;
+ }
+ };
+
+ template <>
+ struct default_value_traits<QString, id_clob>: qstring_lob_value_traits
+ {
+ };
+
+ template <>
+ struct default_value_traits<QString, id_nclob>: qstring_lob_value_traits
+ {
+ };
+
+ 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/libodb-qt/odb/qt/basic/oracle/quuid-traits.hxx b/libodb-qt/odb/qt/basic/oracle/quuid-traits.hxx
new file mode 100644
index 0000000..5f8041e
--- /dev/null
+++ b/libodb-qt/odb/qt/basic/oracle/quuid-traits.hxx
@@ -0,0 +1,70 @@
+// file : odb/qt/basic/oracle/uuid-traits.hxx
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_QT_BASIC_ORACLE_UUID_TRAITS_HXX
+#define ODB_QT_BASIC_ORACLE_UUID_TRAITS_HXX
+
+#include <odb/pre.hxx>
+
+#include <cstring> // std::memcpy
+#include <cassert>
+
+#include <QtCore/QUuid>
+
+#include <odb/oracle/traits.hxx>
+
+namespace odb
+{
+ namespace oracle
+ {
+ template <>
+ struct default_value_traits<QUuid, id_raw>
+ {
+ public:
+ typedef QUuid value_type;
+ typedef value_type query_type;
+ typedef char* image_type;
+
+ static void
+ set_value (value_type& v, const char* b, std::size_t n, bool is_null)
+ {
+ if (!is_null)
+ {
+ assert (n == 16);
+ std::memcpy (&v.data1, b, 16);
+ }
+ else
+ v = QUuid ();
+ }
+
+ static void
+ set_image (char* b,
+ std::size_t c,
+ std::size_t& n,
+ bool& is_null,
+ const value_type& v)
+ {
+ // If we can, store nil as NULL. Otherwise, store it as a value.
+ //
+ is_null = is_null && v.isNull ();
+
+ if (!is_null)
+ {
+ n = 16;
+ assert (c >= n);
+ std::memcpy (b, &v.data1, n);
+ }
+ }
+ };
+
+ template <>
+ struct default_type_traits<QUuid>
+ {
+ static const database_type_id db_type_id = id_raw;
+ };
+ }
+}
+
+#include <odb/post.hxx>
+
+#endif // ODB_QT_BASIC_ORACLE_UUID_TRAITS_HXX