From 9715f388db714fb663b854883e4cad5f2aa3c860 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 2 Sep 2013 08:33:25 +0200 Subject: Support for versioning simple value in object --- odb/pgsql/statement.cxx | 44 +++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 23 deletions(-) (limited to 'odb/pgsql/statement.cxx') diff --git a/odb/pgsql/statement.cxx b/odb/pgsql/statement.cxx index feebe06..b65eb5b 100644 --- a/odb/pgsql/statement.cxx +++ b/odb/pgsql/statement.cxx @@ -228,7 +228,8 @@ namespace odb n.formats[i] = 1; - if (current_bind.is_null != 0 && *current_bind.is_null) + if (current_bind.buffer == 0 || // Skip NULL entries. + (current_bind.is_null != 0 && *current_bind.is_null)) { n.values[i] = 0; n.lengths[i] = 0; @@ -312,19 +313,18 @@ namespace odb bool truncated) { bool r (true); - int int_row (static_cast (row)); + int col_count (PQnfields (result)); - // Make sure that the number of columns in the result returned by - // the database matches the number that we expect. A common cause - // of this assertion is a native view with a number of data members - // not matching the number of columns in the SELECT-list. - // - assert (static_cast (PQnfields (result)) == count); - - for (int i (0); i < static_cast (count); ++i) + int col (0); + for (size_t i (0); i != count && col != col_count; ++i) { const bind& b (p[i]); + if (b.buffer == 0) // Skip NULL entries. + continue; + + int c (col++); + if (truncated && (b.truncated == 0 || !*b.truncated)) continue; @@ -335,13 +335,13 @@ namespace odb // if (!truncated) { - *b.is_null = PQgetisnull (result, int_row, i) == 1; + *b.is_null = PQgetisnull (result, static_cast (row), c) == 1; if (*b.is_null) continue; } - const char* v (PQgetvalue (result, int_row, i)); + const char* v (PQgetvalue (result, static_cast (row), c)); switch (b.type) { @@ -349,47 +349,40 @@ namespace odb { *static_cast (b.buffer) = *reinterpret_cast (v); - break; } case bind::smallint: { *static_cast (b.buffer) = *reinterpret_cast (v); - break; } case bind::integer: { *static_cast (b.buffer) = *reinterpret_cast (v); - break; } case bind::bigint: { *static_cast (b.buffer) = *reinterpret_cast (v); - break; } case bind::real: { *static_cast (b.buffer) = *reinterpret_cast (v); - break; } case bind::double_: { *static_cast (b.buffer) = *reinterpret_cast (v); - break; } case bind::date: { *static_cast (b.buffer) = *reinterpret_cast (v); - break; } case bind::time: @@ -397,7 +390,6 @@ namespace odb { *static_cast (b.buffer) = *reinterpret_cast (v); - break; } case bind::numeric: @@ -406,7 +398,8 @@ namespace odb case bind::bit: case bind::varbit: { - *b.size = static_cast (PQgetlength (result, int_row, i)); + *b.size = static_cast ( + PQgetlength (result, static_cast (row), c)); if (b.capacity < *b.size) { @@ -418,18 +411,23 @@ namespace odb } memcpy (b.buffer, v, *b.size); - break; } case bind::uuid: { memcpy (b.buffer, v, 16); - break; } } } + // Make sure that the number of columns in the result returned by + // the database matches the number that we expect. A common cause + // of this assertion is a native view with a number of data members + // not matching the number of columns in the SELECT-list. + // + assert (col == col_count); + return r; } -- cgit v1.1