diff options
Diffstat (limited to 'odb/sqlite/statements-base.hxx')
-rw-r--r-- | odb/sqlite/statements-base.hxx | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/odb/sqlite/statements-base.hxx b/odb/sqlite/statements-base.hxx index 5db1369..1df53cd 100644 --- a/odb/sqlite/statements-base.hxx +++ b/odb/sqlite/statements-base.hxx @@ -7,10 +7,12 @@ #include <odb/pre.hxx> +#include <odb/schema-version.hxx> #include <odb/details/shared-ptr.hxx> #include <odb/sqlite/version.hxx> -#include <odb/sqlite/forward.hxx> // connection +#include <odb/sqlite/connection.hxx> +#include <odb/sqlite/database.hxx> #include <odb/sqlite/details/export.hxx> @@ -29,18 +31,30 @@ namespace odb return conn_; } + // Schema version. database::schema_version_migration() is thread- + // safe which means it is also slow. Cache the result in statements + // so we can avoid the mutex lock. This is thread-safe since if the + // version is updated, then the statements cache will be expired. + // + const schema_version_migration& + version_migration (const char* name = "") const + { + if (svm_ == 0) + svm_ = &conn_.database ().schema_version_migration (name); + + return *svm_; + } + public: virtual ~statements_base (); protected: - statements_base (connection_type& conn) - : conn_ (conn) - { - } + statements_base (connection_type& conn): conn_ (conn), svm_ (0) {} protected: connection_type& conn_; + mutable const schema_version_migration* svm_; }; } } |