From 66a01c2f277a0118ee4307fcfaf07df81218497e Mon Sep 17 00:00:00 2001 From: Constantin Michael Date: Tue, 15 Nov 2011 11:59:11 +0200 Subject: Support mapping of QByteArray and QString to Oracle LOB types --- odb/qt/basic/oracle/qbyte-array-traits.hxx | 88 +++++++++++++++++++++++++++++- 1 file changed, 87 insertions(+), 1 deletion(-) (limited to 'odb/qt/basic/oracle/qbyte-array-traits.hxx') 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 + { + 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 one_chunk: + case first_chunk: + { + v.clear (); + + // Falling through. + } + case next_chunk: + case last_chunk: + { + 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 = one_chunk; + *s = static_cast (v.size ()); + *b = v.constData (); + + return true; + } + }; + + template <> struct default_type_traits { - static const database_type_id db_type_id = id_raw; + static const database_type_id db_type_id = id_blob; }; } } -- cgit v1.1