From e61fb61f6406db4d1b3b33eb72007ba22efb44bd Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 28 Mar 2011 09:54:19 +0200 Subject: Recode tests to work with implementations lacking result::size() --- libcommon/common/common.cxx | 2 ++ libcommon/common/common.hxx | 21 ++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) (limited to 'libcommon/common') diff --git a/libcommon/common/common.cxx b/libcommon/common/common.cxx index 4ad169c..1ed65e3 100644 --- a/libcommon/common/common.cxx +++ b/libcommon/common/common.cxx @@ -8,6 +8,8 @@ #include +#include + #if defined(DATABASE_MYSQL) # include # include diff --git a/libcommon/common/common.hxx b/libcommon/common/common.hxx index 1862aae..23e9d80 100644 --- a/libcommon/common/common.hxx +++ b/libcommon/common/common.hxx @@ -9,11 +9,30 @@ #include // std::auto_ptr #include // std::size_t -#include +#include // odb::database +#include +#include #include LIBCOMMON_EXPORT std::auto_ptr create_database (int& argc, char* argv[], std::size_t max_connections = 0); +// This function returns an accurate result only if the result iterator +// hasn't been advanced. +// +template +std::size_t +size (odb::result& r) +{ + std::size_t n (0); +#if defined(DATABASE_SQLITE) + for (typename odb::result::iterator i (r.begin ()); i != r.end (); ++i) + n++; +#else + n = r.size (); +#endif + return n; +} + #endif // LIBCOMMON_COMMON_COMMON_HXX -- cgit v1.1