aboutsummaryrefslogtreecommitdiff
path: root/libcommon
diff options
context:
space:
mode:
Diffstat (limited to 'libcommon')
-rw-r--r--libcommon/common/common.cxx2
-rw-r--r--libcommon/common/common.hxx21
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