From e5d0186db99492a139237067bab841a5b83463af Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Wed, 24 Jan 2024 19:01:19 +0300 Subject: Turn libodb-sqlite repository into package for muti-package repository --- libodb-sqlite/odb/sqlite/statement-cache.txx | 60 ++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 libodb-sqlite/odb/sqlite/statement-cache.txx (limited to 'libodb-sqlite/odb/sqlite/statement-cache.txx') diff --git a/libodb-sqlite/odb/sqlite/statement-cache.txx b/libodb-sqlite/odb/sqlite/statement-cache.txx new file mode 100644 index 0000000..c089e32 --- /dev/null +++ b/libodb-sqlite/odb/sqlite/statement-cache.txx @@ -0,0 +1,60 @@ +// file : odb/sqlite/statement-cache.txx +// license : GNU GPL v2; see accompanying LICENSE file + +#include + +namespace odb +{ + namespace sqlite + { + template + typename object_traits_impl::statements_type& + statement_cache:: + find_object () + { + typedef + typename object_traits_impl::statements_type + statements_type; + + // Clear the cache if the database version has changed. This + // makes sure we don't re-use statements that correspond to + // the old schema. + // + if (version_seq_ != conn_.database ().schema_version_sequence ()) + { + map_.clear (); + version_seq_ = conn_.database ().schema_version_sequence (); + } + + map::iterator i (map_.find (&typeid (T))); + + if (i != map_.end ()) + return static_cast (*i->second); + + details::shared_ptr p ( + new (details::shared) statements_type (conn_)); + + map_.insert (map::value_type (&typeid (T), p)); + return *p; + } + + template + view_statements& statement_cache:: + find_view () + { + // We don't cache any statements for views so no need to clear + // the cache. + + map::iterator i (map_.find (&typeid (T))); + + if (i != map_.end ()) + return static_cast&> (*i->second); + + details::shared_ptr > p ( + new (details::shared) view_statements (conn_)); + + map_.insert (map::value_type (&typeid (T), p)); + return *p; + } + } +} -- cgit v1.1