diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2011-03-28 09:54:19 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2011-03-28 09:54:19 +0200 |
commit | e61fb61f6406db4d1b3b33eb72007ba22efb44bd (patch) | |
tree | 0dff61043ebda523eff7451b8f210d395ef4b9f0 /libcommon/common | |
parent | 3de8e4843bc85f9fc6e63c1a4fea6b57ff0351b6 (diff) |
Recode tests to work with implementations lacking result::size()
Diffstat (limited to 'libcommon/common')
-rw-r--r-- | libcommon/common/common.cxx | 2 | ||||
-rw-r--r-- | libcommon/common/common.hxx | 21 |
2 files changed, 22 insertions, 1 deletions
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 <common/config.hxx> +#include <odb/database.hxx> + #if defined(DATABASE_MYSQL) # include <odb/mysql/database.hxx> # include <odb/mysql/connection-factory.hxx> 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 <memory> // std::auto_ptr #include <cstddef> // std::size_t -#include <odb/database.hxx> +#include <odb/forward.hxx> // odb::database +#include <odb/result.hxx> +#include <common/config.hxx> #include <common/export.hxx> LIBCOMMON_EXPORT std::auto_ptr<odb::database> 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 <typename T> +std::size_t +size (odb::result<T>& r) +{ + std::size_t n (0); +#if defined(DATABASE_SQLITE) + for (typename odb::result<T>::iterator i (r.begin ()); i != r.end (); ++i) + n++; +#else + n = r.size (); +#endif + return n; +} + #endif // LIBCOMMON_COMMON_COMMON_HXX |