diff options
Diffstat (limited to 'libcommon/common/common.hxx')
-rw-r--r-- | libcommon/common/common.hxx | 21 |
1 files changed, 20 insertions, 1 deletions
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 |