diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2024-01-25 18:52:59 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2024-01-25 18:52:59 +0300 |
commit | 3a160a80c788d81e48acf19a2cf68f29cf125dae (patch) | |
tree | 8bf000b3ae959d56367c15aa214a95d24b096905 /libodb-mysql/odb/mysql/statements-base.hxx | |
parent | 35bdfb3e3604527f36f046928324346e8b37b46b (diff) |
Turn libodb-mysql repository into package for muti-package repositorylibodb-mysql
Diffstat (limited to 'libodb-mysql/odb/mysql/statements-base.hxx')
-rw-r--r-- | libodb-mysql/odb/mysql/statements-base.hxx | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/libodb-mysql/odb/mysql/statements-base.hxx b/libodb-mysql/odb/mysql/statements-base.hxx new file mode 100644 index 0000000..93e72d2 --- /dev/null +++ b/libodb-mysql/odb/mysql/statements-base.hxx @@ -0,0 +1,63 @@ +// file : odb/mysql/statements-base.hxx +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_MYSQL_STATEMENTS_BASE_HXX +#define ODB_MYSQL_STATEMENTS_BASE_HXX + +#include <odb/pre.hxx> + +#include <odb/schema-version.hxx> +#include <odb/details/shared-ptr.hxx> + +#include <odb/mysql/version.hxx> +#include <odb/mysql/connection.hxx> +#include <odb/mysql/database.hxx> + +#include <odb/mysql/details/export.hxx> + +namespace odb +{ + namespace mysql + { + class LIBODB_MYSQL_EXPORT statements_base: public details::shared_base + { + public: + typedef mysql::connection connection_type; + + connection_type& + connection () + { + 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), svm_ (0) {} + + protected: + connection_type& conn_; + mutable const schema_version_migration* svm_; + }; + } +} + +#include <odb/post.hxx> + +#endif // ODB_MYSQL_STATEMENTS_BASE_HXX |