aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConstantin Michael <constantin@codesynthesis.com>2011-05-26 16:29:30 +0200
committerConstantin Michael <constantin@codesynthesis.com>2011-05-26 16:29:30 +0200
commitf54e9e5f2776aae188efc38fd25c5b25a7c2f052 (patch)
treee77cf6797dddaf1f515fdf3fe886193a97ea8633
parent3f94b73f025f2fa3e08edf07270225c4a5c391c1 (diff)
Complete statement::bind_result implementation
-rw-r--r--odb/pgsql/statement.cxx42
1 files changed, 26 insertions, 16 deletions
diff --git a/odb/pgsql/statement.cxx b/odb/pgsql/statement.cxx
index c53fec0..5e9007d 100644
--- a/odb/pgsql/statement.cxx
+++ b/odb/pgsql/statement.cxx
@@ -13,6 +13,7 @@
#include <odb/pgsql/connection.hxx>
#include <odb/pgsql/transaction.hxx>
#include <odb/pgsql/error.hxx>
+#include <odb/pgsql/endian-traits.hxx>
using namespace std;
@@ -128,35 +129,46 @@ namespace odb
continue;
}
- // @@ Revise this.
- //
- size_t buffer_len;
-
switch (b.type)
{
case bind::smallint:
{
- buffer_len = 2;
+ *static_cast<short*> (b.buffer) = endian_traits::ntoh (
+ *reinterpret_cast<short*> (
+ PQgetvalue (result, static_cast<int> (row), i)));
+
break;
}
case bind::integer:
{
- buffer_len = 4;
+ *static_cast<int*> (b.buffer) = endian_traits::ntoh (
+ *reinterpret_cast<int*> (
+ PQgetvalue (result, static_cast<int> (row), i)));
+
break;
}
case bind::bigint:
{
- buffer_len = 8;
+ *static_cast<long long*> (b.buffer) =
+ endian_traits::ntoh (*reinterpret_cast<long long*> (
+ PQgetvalue (result, static_cast<int> (row), i)));
+
break;
}
case bind::real:
{
- buffer_len = 4;
+ *static_cast<float*> (b.buffer) = endian_traits::ntoh (
+ *reinterpret_cast<float*> (
+ PQgetvalue (result, static_cast<int> (row), i)));
+
break;
}
case bind::double_:
{
- buffer_len = 8;
+ *static_cast<double*> (b.buffer) = endian_traits::ntoh (
+ *reinterpret_cast<double*> (
+ PQgetvalue (result, static_cast<int> (row), i)));
+
break;
}
case bind::numeric:
@@ -164,11 +176,9 @@ namespace odb
case bind::bytea:
default:
{
- buffer_len = static_cast<size_t> (
+ *b.size = static_cast<size_t> (
PQgetlength (result, static_cast<int> (row), i));
- *b.size = buffer_len;
-
if (b.capacity < *b.size)
{
if (b.truncated)
@@ -178,13 +188,13 @@ namespace odb
continue;
}
+ memcpy (b.buffer,
+ PQgetvalue (result, static_cast<int> (row), i),
+ *b.size);
+
break;
}
};
-
- memcpy (b.buffer,
- PQgetvalue (result, static_cast<int> (row), i),
- buffer_len);
}
return r;