diff options
-rw-r--r-- | odb/database.cxx | 33 | ||||
-rw-r--r-- | odb/database.hxx | 20 | ||||
-rw-r--r-- | odb/database.ixx | 39 |
3 files changed, 58 insertions, 34 deletions
diff --git a/odb/database.cxx b/odb/database.cxx index ad71b4f..c9692ba 100644 --- a/odb/database.cxx +++ b/odb/database.cxx @@ -4,6 +4,8 @@ #include <odb/database.hxx> +using namespace std; + namespace odb { database:: @@ -17,4 +19,35 @@ namespace odb connection_type& c (transaction::current ().connection ()); return c.execute (st, n); } + + const database::schema_version_info& database:: + schema_version_migration_ (const string& name) const + { + schema_version_map::const_iterator i (schema_version_map_.find (name)); + const schema_version_info& svi ( + i != schema_version_map_.end () && i->second.version != 0 + ? i->second + : load_schema_version (name)); + + if (default_schema_version_ == 0 && name.empty ()) + default_schema_version_ = &svi; + + return svi; + } + + void database:: + schema_version_migration (const schema_version_migration_type& svm, + const string& name) + { + schema_version_info& svi (schema_version_map_[name]); + if (svi.version != svm.version || svi.migration != svm.migration) + { + svi.version = svm.version; + svi.migration = svm.migration; + schema_version_seq_++; + } + + if (default_schema_version_ == 0 && name.empty ()) + default_schema_version_ = &svi; + } } diff --git a/odb/database.hxx b/odb/database.hxx index c7c4598..7ddbecb 100644 --- a/odb/database.hxx +++ b/odb/database.hxx @@ -339,24 +339,29 @@ namespace odb typedef odb::schema_version_migration schema_version_migration_type; schema_version_type - schema_version (const std::string& schema_name = "") const; + schema_version (const std::string& schema_name = std::string ()) const; bool - schema_migration (const std::string& schema_name = "") const; + schema_migration (const std::string& schema_name = std::string ()) const; + // Note that there is code that relies on the returned reference + // being valid until the version is changed or the database instance + // is destroyed. + // const schema_version_migration_type& - schema_version_migration (const std::string& schema_name = "") const; + schema_version_migration ( + const std::string& schema_name = std::string ()) const; // Set schema version and migration state manually. // void schema_version_migration (schema_version_type, bool migration, - const std::string& schema_name = ""); + const std::string& schema_name = std::string ()); void schema_version_migration (const schema_version_migration_type&, - const std::string& schema_name = ""); + const std::string& schema_name = std::string ()); // Set default schema version table for all schema names. The table // name should already be quoted if necessary. @@ -386,6 +391,10 @@ namespace odb virtual const schema_version_info& load_schema_version (const std::string& schema_name) const = 0; + private: + const schema_version_info& + schema_version_migration_ (const std::string& schema_name) const; + // Database id. // public: @@ -478,6 +487,7 @@ namespace odb std::string schema_version_table_; mutable schema_version_map schema_version_map_; + mutable const schema_version_info* default_schema_version_; // Cached. unsigned int schema_version_seq_; }; } diff --git a/odb/database.ixx b/odb/database.ixx index 3de5bbc..378a376 100644 --- a/odb/database.ixx +++ b/odb/database.ixx @@ -11,7 +11,10 @@ namespace odb { inline database:: database (database_id id) - : id_ (id), tracer_ (0), schema_version_seq_ (1) + : id_ (id), + tracer_ (0), + default_schema_version_ (0), + schema_version_seq_ (1) { } @@ -36,14 +39,11 @@ namespace odb inline const database::schema_version_migration_type& database:: schema_version_migration (const std::string& name) const { - // Note that there is code that relies on the returned reference - // being valid until the version is changed or the database instance - // is destroyed. - // - schema_version_map::const_iterator i (schema_version_map_.find (name)); - return i != schema_version_map_.end () && i->second.version != 0 - ? i->second - : load_schema_version (name); + return name.empty () && + default_schema_version_ != 0 && + default_schema_version_->version != 0 + ? *default_schema_version_ + : schema_version_migration_ (name); } inline void database:: @@ -51,26 +51,7 @@ namespace odb bool m, const std::string& name) { - schema_version_info& svi (schema_version_map_[name]); - if (svi.version != v || svi.migration != m) - { - svi.version = v; - svi.migration = m; - schema_version_seq_++; - } - } - - inline void database:: - schema_version_migration (const schema_version_migration_type& svm, - const std::string& name) - { - schema_version_info& svi (schema_version_map_[name]); - if (svi.version != svm.version || svi.migration != svm.migration) - { - svi.version = svm.version; - svi.migration = svm.migration; - schema_version_seq_++; - } + schema_version_migration (schema_version_migration_type (v, m), name); } inline void database:: |