aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConstantin Michael <constantin@codesynthesis.com>2011-11-15 11:59:11 +0200
committerConstantin Michael <constantin@codesynthesis.com>2011-11-16 11:16:04 +0200
commit66a01c2f277a0118ee4307fcfaf07df81218497e (patch)
tree2d0e3a60467bd3f70e3fbea5e6d676d5bb1d7f6c
parentf10c9f20e8d32330c9f4ab46a638ab5556cb61b8 (diff)
Support mapping of QByteArray and QString to Oracle LOB types
-rw-r--r--odb/qt/basic/oracle/qbyte-array-traits.hxx88
-rw-r--r--odb/qt/basic/oracle/qstring-traits.hxx124
2 files changed, 211 insertions, 1 deletions
diff --git a/odb/qt/basic/oracle/qbyte-array-traits.hxx b/odb/qt/basic/oracle/qbyte-array-traits.hxx
index 3d99cd7..063d52d 100644
--- a/odb/qt/basic/oracle/qbyte-array-traits.hxx
+++ b/odb/qt/basic/oracle/qbyte-array-traits.hxx
@@ -68,9 +68,95 @@ namespace odb
};
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 one_chunk:
+ case first_chunk:
+ {
+ v.clear ();
+
+ // Falling through.
+ }
+ case next_chunk:
+ case last_chunk:
+ {
+ 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 = one_chunk;
+ *s = static_cast<ub4> (v.size ());
+ *b = v.constData ();
+
+ return true;
+ }
+ };
+
+ template <>
struct default_type_traits<QByteArray>
{
- static const database_type_id db_type_id = id_raw;
+ static const database_type_id db_type_id = id_blob;
};
}
}
diff --git a/odb/qt/basic/oracle/qstring-traits.hxx b/odb/qt/basic/oracle/qstring-traits.hxx
index c0b6775..bca7bab 100644
--- a/odb/qt/basic/oracle/qstring-traits.hxx
+++ b/odb/qt/basic/oracle/qstring-traits.hxx
@@ -64,6 +64,130 @@ namespace odb
}
};
+ 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 one_chunk:
+ case first_chunk:
+ {
+ v.clear ();
+
+ // Falling through.
+ }
+ case next_chunk:
+ case last_chunk:
+ {
+ 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 = one_chunk;
+ else
+ {
+ *s = capacity;
+ *p = first_chunk;
+ }
+ }
+ else
+ {
+ *s -= *position_context;
+
+ if (*s <= capacity)
+ *p = last_chunk;
+ else
+ {
+ *s = capacity;
+ *p = next_chunk;
+ }
+ }
+
+ std::memcpy (temp_buffer, v.constData () + *position_context, *s);
+ *b = temp_buffer;
+ *position_context += *s;
+
+ return true;
+ }
+ };
+
+ template <>
+ struct LIBODB_ORACLE_EXPORT default_value_traits<QString, id_clob>:
+ qstring_lob_value_traits
+ {
+ };
+
+ template <>
+ struct LIBODB_ORACLE_EXPORT default_value_traits<QString, id_nclob>:
+ qstring_lob_value_traits
+ {
+ };
+
template <>
struct default_type_traits<QString>
{