aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConstantin Michael <constantin@codesynthesis.com>2011-10-11 08:25:30 +0200
committerConstantin Michael <constantin@codesynthesis.com>2011-10-14 13:12:02 +0200
commitd8227f949940cd83ebf7d349b1e97d116474758b (patch)
tree807a400d92462072004a2c431e94aa999dc5bb0b
parent6a2421094edb84224b0c7d02690522f3f7b8a86c (diff)
Allow for size to be returned from big_int set_image functions
The OCI interface requires size information for any buffer passed to its bind interface. By adding a return path for this data, we avert any need to obtain this from the actual VARNUM binary data using messy byte manipulation.
-rw-r--r--odb/oracle/details/number.cxx10
-rw-r--r--odb/oracle/details/number.hxx7
-rw-r--r--odb/oracle/traits.hxx46
3 files changed, 51 insertions, 12 deletions
diff --git a/odb/oracle/details/number.cxx b/odb/oracle/details/number.cxx
index 044a99b..d328b1f 100644
--- a/odb/oracle/details/number.cxx
+++ b/odb/oracle/details/number.cxx
@@ -102,7 +102,7 @@ namespace odb
}
void
- int64_to_number (char* b, long long v)
+ int64_to_number (char* b, size_t& n, long long v)
{
// We assume that b is long enough to contain a long long VARNUM
// representation, that being 12 bytes.
@@ -121,8 +121,8 @@ namespace odb
}
bool sig (false);
- size_t n (0);
unsigned char t[11], *m (t);
+ n = 0;
if (v < 0)
{
@@ -169,6 +169,7 @@ namespace odb
// Set the length.
//
ub[0] = static_cast<unsigned char> (m - t + 1);
+ n = static_cast<size_t> (ub[0] + 1);
// Set the significant digits in big-endian byte order and the
// terminator, if any.
@@ -227,7 +228,7 @@ namespace odb
}
void
- uint64_to_number (char* b, unsigned long long v)
+ uint64_to_number (char* b, size_t& n, unsigned long long v)
{
// We assume that b is long enough to contain an unsigned long long
// VARNUM representation, that being 12 bytes.
@@ -246,8 +247,8 @@ namespace odb
}
bool sig (false);
- size_t n (0);
unsigned char t[11], *m (t);
+ n = 0;
while (v != 0)
{
@@ -268,6 +269,7 @@ namespace odb
// Set the length.
//
ub[0] = static_cast<unsigned char> (m - t + 1);
+ n = static_cast<size_t> (ub[0] + 1);
// Set the significant digits in big-endian byte order.
//
diff --git a/odb/oracle/details/number.hxx b/odb/oracle/details/number.hxx
index fe355da..90fb038 100644
--- a/odb/oracle/details/number.hxx
+++ b/odb/oracle/details/number.hxx
@@ -7,6 +7,9 @@
#define ODB_ORACLE_NUMBER_HXX
#include <odb/pre.hxx>
+
+#include <cstddef> // std::size_t
+
#include <odb/oracle/details/export.hxx>
namespace odb
@@ -27,13 +30,13 @@ namespace odb
number_to_int64 (const char* buffer);
LIBODB_ORACLE_EXPORT void
- int64_to_number (char* buffer, long long value);
+ int64_to_number (char* buffer, std::size_t& n, long long val);
LIBODB_ORACLE_EXPORT unsigned long long
number_to_uint64 (const char* buffer);
LIBODB_ORACLE_EXPORT void
- uint64_to_number (char* buffer, unsigned long long value);
+ uint64_to_number (char* buffer, std::size_t& n, unsigned long long val);
}
}
}
diff --git a/odb/oracle/traits.hxx b/odb/oracle/traits.hxx
index eafa2a4..b5dfc80 100644
--- a/odb/oracle/traits.hxx
+++ b/odb/oracle/traits.hxx
@@ -260,7 +260,21 @@ namespace odb
vtraits::set_image (i, is_null, wtraits::get_ref (v));
}
- // big_int, big_float, timestamp, string, nstring, raw.
+ // big_int, big_float.
+ //
+ static void
+ set_value (W& v, const char* i, bool is_null)
+ {
+ vtraits::set_value (wtraits::set_ref (v), i, is_null);
+ }
+
+ static void
+ set_image (char* i, std::size_t& n, bool& is_null, const W& v)
+ {
+ vtraits::set_image (i, n, is_null, wtraits::get_ref (v));
+ }
+
+ // timestamp, string, nstring, raw.
//
static void
set_value (W& v, const char* i, std::size_t n, bool is_null)
@@ -326,7 +340,27 @@ namespace odb
vtraits::set_image (i, is_null, wtraits::get_ref (v));
}
- // big_int, big_float, timestamp, string, nstring, raw.
+ // big_int, big_float.
+ //
+ static void
+ set_value (W& v, const char& i, bool is_null)
+ {
+ if (is_null)
+ wtraits::set_null (v);
+ else
+ vtraits::set_value (wtraits::set_ref (v), i, is_null);
+ }
+
+ static void
+ set_image (char* i, std::size_t& n, bool& is_null, const W& v)
+ {
+ is_null = wtraits::get_null (v);
+
+ if (!is_null)
+ vtraits::set_image (i, n, is_null, wtraits::get_ref (v));
+ }
+
+ // timestamp, string, nstring, raw.
//
static void
set_value (W& v, const char* i, std::size_t n, bool is_null)
@@ -416,10 +450,10 @@ namespace odb
}
static void
- set_image (char* b, bool& is_null, T v)
+ set_image (char* b, std::size_t& n, bool& is_null, T v)
{
is_null = false;
- details::int64_to_number (b, static_cast<long long> (v));
+ details::int64_to_number (b, n, static_cast<long long> (v));
}
};
@@ -436,10 +470,10 @@ namespace odb
}
static void
- set_image (char* b, bool& is_null, T v)
+ set_image (char* b, std::size_t& n, bool& is_null, T v)
{
is_null = false;
- details::uint64_to_number (b, static_cast<unsigned long long> (v));
+ details::uint64_to_number (b, n, static_cast<unsigned long long> (v));
}
};