diff options
author | Constantin Michael <constantin@codesynthesis.com> | 2011-10-14 14:07:39 +0200 |
---|---|---|
committer | Constantin Michael <constantin@codesynthesis.com> | 2011-10-14 14:33:16 +0200 |
commit | bbac9d4b7e9015811ad3dd3d49024981e7fce73d (patch) | |
tree | 04d92632e8e30315555412fb70d90f01245cdc29 | |
parent | 4b140934ad3c685b35f17719417cf760b62ae1f0 (diff) |
Correct the LOB callback aspects of the bind mechanism
The parameter callback context must be const qualified. This is both sensible
and necessary to avoid unecessary casts in the generated code during image
manipulation. The result callback context must not be const qualified as the
result callback should be permitted to modify it.
Both the callback and context members of the bind structure must be pointers
to the relevant union types in order for the binding mechanism to work
correctly.
-rw-r--r-- | odb/oracle/oracle-types.hxx | 10 | ||||
-rw-r--r-- | odb/oracle/statement.cxx | 25 | ||||
-rw-r--r-- | odb/oracle/traits.hxx | 4 |
3 files changed, 22 insertions, 17 deletions
diff --git a/odb/oracle/oracle-types.hxx b/odb/oracle/oracle-types.hxx index 5864d0a..091a6d5 100644 --- a/odb/oracle/oracle-types.hxx +++ b/odb/oracle/oracle-types.hxx @@ -59,6 +59,12 @@ namespace odb result_callback_type result; }; + union lob_context + { + const void* param; + void* result; + }; + struct bind { // This enumeration identifies the possible buffer types that can be @@ -101,12 +107,12 @@ namespace odb // buffer. sb2* indicator; // Pointer to an OCI indicator variable. - lob_callback callback; + lob_callback* callback; // This pointer is provided to the user through the context argument // in both parameter and result callback functions. // - void* callback_context; + lob_context* context; }; } } diff --git a/odb/oracle/statement.cxx b/odb/oracle/statement.cxx index af70aca..ff02f06 100644 --- a/odb/oracle/statement.cxx +++ b/odb/oracle/statement.cxx @@ -80,13 +80,13 @@ namespace odb if (*b.indicator != -1) { chunk_position pos; - if (!(*b.callback.param) (&b.callback_context, - reinterpret_cast<ub4*> (b.size), - const_cast<const void**> (buffer), - size, - &pos, - b.buffer, - b.capacity)) + if (!(*b.callback->param) (b.context->param, + reinterpret_cast<ub4*> (b.size), + const_cast<const void**> (buffer), + size, + &pos, + b.buffer, + b.capacity)) return OCI_ERROR; switch (pos) @@ -350,8 +350,7 @@ namespace odb if ((b->type == bind::blob || b->type == bind::clob || b->type == bind::nclob) && - *b->indicator != -1 && - b->callback.result != 0) + *b->indicator != -1 && b->callback->result != 0) { // If b->capacity is 0, we will be stuck in an infinite loop. // @@ -404,10 +403,10 @@ namespace odb // OCI generates and ORA-24343 error when an error code is // returned from a user callback. We simulate this. // - if (!(*b->callback.result) (b->callback_context, - b->buffer, - static_cast<ub4> (read), - cp)) + if (!(*b->callback->result) (b->context->result, + b->buffer, + static_cast<ub4> (read), + cp)) throw database_exception (24343, "user defined callback error"); } while (r == OCI_NEED_DATA); diff --git a/odb/oracle/traits.hxx b/odb/oracle/traits.hxx index a8ada63..d156fb3 100644 --- a/odb/oracle/traits.hxx +++ b/odb/oracle/traits.hxx @@ -302,7 +302,7 @@ namespace odb static void set_image (param_callback_type& cb, - void*& context, + const void*& context, bool& is_null, const W& v) { @@ -397,7 +397,7 @@ namespace odb static void set_image (param_callback_type& cb, - void*& context, + const void*& context, bool& is_null, const W& v) { |