diff --git a/README.md b/README.md index 17a7f37..5d3a52e 100644 --- a/README.md +++ b/README.md @@ -281,6 +281,11 @@ Sets test architecture to x64. Open test explorer and click Run All. And then rebuild the project, you can see test items in test explorer. ## Version and History +- 0.93 * Update : db-update project is converted to CLR + * Fix : catchup_schema() function supports localized temp dir name. + * Add : Support VS2019. +- 0.92 * Fix : Supress useless debug log file creation. +- 0.90 * Fix : Support localized db name. - 0.89 * use SOCI 4.0.3 and BOOST 1.80.0. Add c++17 option. - 0.88 * use SOCI 4.0. * Add some pragma after connect to sqllite database. @@ -301,7 +306,7 @@ And then rebuild the project, you can see test items in test explorer. ## Licenses and Authors * Licensed under the [Boost Software License 1.0] - * Copyright © 2014-2016 Kou Ouchi + * Copyright © 2014-2022 Kou Ouchi ## Related Information - [Enterprise Architect] : Data Modeling editor. "CodeEngineering" function can generates DDL of various DataBase Systems. diff --git a/core/include/og/core/session.h b/core/include/og/core/session.h index c25a92b..9386681 100644 --- a/core/include/og/core/session.h +++ b/core/include/og/core/session.h @@ -34,7 +34,7 @@ class session bool import_from_file(string _path); void export_to_file(string _path); void export_object_to_recursively(string _id, string _path); - bool catchup_schema(string _path); + bool catchup_schema(string _path, string _tempdir); bool reload_schema(string _path, string _sess_tmp); OG_COREAPI void build(); void open(string _connection_string); diff --git a/core/include/og/og_session.h b/core/include/og/og_session.h index e08104c..37d7026 100644 --- a/core/include/og/og_session.h +++ b/core/include/og/og_session.h @@ -34,7 +34,7 @@ class og_session /////////////////////////////// OG_COREAPI bool import_from_file(string _path); OG_COREAPI void export_to_file(string _path); - OG_COREAPI bool catchup_schema(string _path); + OG_COREAPI bool catchup_schema(string _path, string _tempdir); OG_COREAPI bool reload_schema(string _path, string _sesn_path); OG_COREAPI boost::optional import_object_from_file(string _path); diff --git a/core/src/og_session.cpp b/core/src/og_session.cpp index ee525de..f1a9698 100644 --- a/core/src/og_session.cpp +++ b/core/src/og_session.cpp @@ -62,9 +62,9 @@ void og_session::export_to_file(string _path) { session_->export_to_file(_path); } -bool og_session::catchup_schema(string _path) +bool og_session::catchup_schema(string _path, string _tempdir) { - return session_->catchup_schema(_path); + return session_->catchup_schema(_path, _tempdir); } bool og_session::reload_schema(string _path, string _sesn_path) { diff --git a/core/src/session.cpp b/core/src/session.cpp index a2d41ee..1cf8730 100644 --- a/core/src/session.cpp +++ b/core/src/session.cpp @@ -1224,13 +1224,13 @@ bool session::import_from_file(string _path) boost::property_tree::ptree pt; xml_stream().read_from_file(_path, &pt); + OG_LOG << "import session object."; + int count_object = 0; // session object BOOST_FOREACH(ptree::value_type & child, pt.get_child("og.session.objects")) { - OG_LOG << "import session object:" << count_object++; - session_object_ptr sesn_obj(new session_object(this)); // deserialize @@ -1252,58 +1252,79 @@ bool session::import_from_file(string _path) sesn_obj->set_schema_object(schm_objs.front()); } - if (!import_object(sesn_obj, child.second)) { continue; } + if (!import_object(sesn_obj, child.second)) + { + continue; + } + else + { + count_object++; + } } } } - // session relation - int count_relation = 0; - BOOST_FOREACH(ptree::value_type & child, - pt.get_child("og.session.relations")) - { - OG_LOG << "import session relation:" << count_relation++; - - session_relation_ptr sesn_rel(new session_relation(this)); + OG_LOG << "imported session objects:" << count_object; - // deserialize - if (serializer::deserialize(child, sesn_rel)) + auto pt_og_session_relations = pt.get_child_optional("og.session.relations"); + if (pt_og_session_relations.is_initialized()) + { + // session relation + int count_relation = 0; + BOOST_FOREACH(ptree::value_type & child, + pt_og_session_relations.get()) { - boost::optional schm_rel = - schema_->get_relation(sesn_rel->get_schema_relation_id()); + OG_LOG << "import session relation:" << count_relation++; - if (schm_rel.is_initialized()) - { - if (schm_rel.get()->get_type().compare(schema::schema_property_object_type_) == - 0) - { - list prep; - list schm_rels; - prep.push_back(schema::schema_property_object_type_); + session_relation_ptr sesn_rel(new session_relation(this)); - schema_->get_relation_by_type(prep, &schm_rels); - sesn_rel->set_schema_relation(schm_rels.front()); - } - - // check from/to - boost::optional sesn_from = - get_object(sesn_rel->get_from_id()); - boost::optional sesn_to = - get_object(sesn_rel->get_to_id()); + // deserialize + if (serializer::deserialize(child, sesn_rel)) + { + boost::optional schm_rel = + schema_->get_relation(sesn_rel->get_schema_relation_id()); - if (sesn_from.is_initialized() && sesn_to.is_initialized()) + if (schm_rel.is_initialized()) { - if (!import_relation(sesn_rel, child.second)) { continue; } + if (schm_rel.get()->get_type().compare(schema::schema_property_object_type_) == + 0) + { + list prep; + list schm_rels; + prep.push_back(schema::schema_property_object_type_); + + schema_->get_relation_by_type(prep, &schm_rels); + sesn_rel->set_schema_relation(schm_rels.front()); + } + + // check from/to + boost::optional sesn_from = + get_object(sesn_rel->get_from_id()); + boost::optional sesn_to = + get_object(sesn_rel->get_to_id()); + + if (sesn_from.is_initialized() && sesn_to.is_initialized()) + { + if (!import_relation(sesn_rel, child.second)) { continue; } + } } } } } + else + { + OG_LOG << "import session relation is skipped."; + } if (get_property_object() == nullptr) { OG_LOG << "building property."; build_property_object(); } + else + { + OG_LOG << "building property is skipped."; + } return true; } @@ -1550,7 +1571,7 @@ void session::sync_relation_parameter( } } -bool session::catchup_schema(string _path) +bool session::catchup_schema(string _path, string _tempdir) { OG_LOG << "catchup_schema start."; @@ -1577,16 +1598,16 @@ bool session::catchup_schema(string _path) return true; } - char* tempdir = nullptr; - size_t sz = 0; - if (!_dupenv_s(&tempdir, &sz, "TEMP") == 0 && tempdir != nullptr) - { - throw og::core::exception() << exception_message("schema file is not found."); - } stringstream session_tempname, schema_tempname; - session_tempname << tempdir << "/SESSION-%%%%-%%%%-%%%%-%%%%.xml.gz"; - schema_tempname << tempdir << "/SCHEMA-%%%%-%%%%-%%%%-%%%%.xml.gz"; - free(tempdir); + session_tempname << _tempdir << "/SESSION-%%%%-%%%%-%%%%-%%%%.xml.gz"; + schema_tempname << _tempdir << "/SCHEMA-%%%%-%%%%-%%%%-%%%%.xml.gz"; + + OG_LOG << "temp dir : " << _tempdir; + + fs::path temp_dir(_tempdir); + + OG_LOG << "check temp dir : " << (fs::is_directory(temp_dir) ? "ok" : "ng"); + fs::path session_temp = fs::unique_path(session_tempname.str()); fs::path schema_temp = fs::unique_path(schema_tempname.str()); diff --git a/etc/Script/og_setup.iss b/etc/Script/og_setup.iss index 2384cdf..dd61924 100644 --- a/etc/Script/og_setup.iss +++ b/etc/Script/og_setup.iss @@ -1,5 +1,5 @@ #define MyAppSetupName 'ObjectGenoise' -#define MyAppVersion '0.92' +#define MyAppVersion '0.93' [Setup] AppId=ObjectGenoise diff --git a/og-net/src/OGSession.cpp b/og-net/src/OGSession.cpp index 18a8264..fbdb683 100644 --- a/og-net/src/OGSession.cpp +++ b/og-net/src/OGSession.cpp @@ -358,10 +358,15 @@ void OGSession::disconnect(String^ _rel_id) bool OGSession::catchup_schema(String^ _path) { - std::string str; - OGConverter::convert_clr_to_std(_path, &str); + Encoding^ u8 = Encoding::UTF8; + cli::array^ bytes_path = u8->GetBytes(_path); + pin_ptr file_path = &bytes_path[0]; + + String^ tempdir = System::IO::Path::GetTempPath(); + cli::array^ bytes_temp_dir = u8->GetBytes(tempdir); + pin_ptr tempdir_str = &bytes_temp_dir[0]; - return og_session_->catchup_schema(str); + return og_session_->catchup_schema((const char*)file_path, (const char*)tempdir_str); } OGSessionObject^ OGSession::get_property_object() diff --git a/test-core/src/unittest_etc.cpp b/test-core/src/unittest_etc.cpp index 73a24d0..8ac24ec 100644 --- a/test-core/src/unittest_etc.cpp +++ b/test-core/src/unittest_etc.cpp @@ -429,7 +429,7 @@ BOOST_AUTO_TEST_CASE(etc_1003_schema_catchup) cleaned_session_.schema()->import_from_file("schema_xml_catchup0.xml.gz"); cleaned_session_.import_from_file("session_xml_catchup0.xml.gz"); - bool res = cleaned_session_.catchup_schema("schema_xml_catchup1.xml.gz"); + bool res = cleaned_session_.catchup_schema("schema_xml_catchup1.xml.gz", /*temp dir*/"."); BOOST_REQUIRE_EQUAL(true, res); @@ -501,14 +501,14 @@ BOOST_AUTO_TEST_CASE(etc_1003_schema_catchup) cleaned_session_.schema()->export_to_file("rev100.xml.gz"); schm_prop->set_revision("99"); - cleaned_session_.catchup_schema("rev100.xml.gz"); + cleaned_session_.catchup_schema("rev100.xml.gz", /*temp dir*/"."); og::og_schema_object_ptr schm_prop2 = cleaned_session_.schema()->get_property_object(); BOOST_REQUIRE_EQUAL(schm_prop2->get_revision(), "100"); schm_prop2->set_revision("101"); - cleaned_session_.catchup_schema("rev100.xml.gz"); + cleaned_session_.catchup_schema("rev100.xml.gz", /*temp dir*/"."); og::og_schema_object_ptr schm_prop3 = cleaned_session_.schema()->get_property_object(); diff --git a/util/db-updater/CMakeLists.txt b/util/db-updater/CMakeLists.txt index b650858..99a981d 100644 --- a/util/db-updater/CMakeLists.txt +++ b/util/db-updater/CMakeLists.txt @@ -100,6 +100,9 @@ set_directory_properties(PROPERTIES ) set_target_properties(db-updater PROPERTIES COTIRE_ADD_UNITY_BUILD FALSE) +set_target_properties(db-updater PROPERTIES COMPILE_FLAGS "/clr /EHa") +set_property(TARGET db-updater PROPERTY OUTPUT_NAME "db-updater") + # # install # diff --git a/util/db-updater/db-updater.cpp b/util/db-updater/db-updater.cpp index 20b0bfa..4d097cf 100644 --- a/util/db-updater/db-updater.cpp +++ b/util/db-updater/db-updater.cpp @@ -1,16 +1,17 @@ #include #include -#include #include #include "og/og_session.h" using namespace std; -using namespace boost::filesystem; +using namespace System; +using namespace System::Security; +using namespace System::IO; void PrintUsage(string mes) { - cout << "db-updater(20170405)" << endl; + cout << "db-updater(20221103)" << endl; cout << "usage: [db file] [schema file]" << endl; cout << endl; cout << mes << endl; @@ -25,15 +26,16 @@ int main(int argc, char* argv[]) exit(1); } - path db(argv[1]); - path schema(argv[2]); + System::String^ db = gcnew System::String(argv[1]); + System::String^ schema = gcnew System::String(argv[2]); + System::Text::Encoding^ u8 = System::Text::Encoding::UTF8; - if (!exists(db)) + if (!File::Exists(db)) { PrintUsage("arg 0 is not exists."); exit(1); } - if (!exists(schema)) + if (!File::Exists(schema)) { PrintUsage("arg 1 is not exists."); exit(1); @@ -43,6 +45,10 @@ int main(int argc, char* argv[]) try { + System::String^ arg1str = gcnew System::String(argv[1]); + cli::array^ bytes_arg1 = u8->GetBytes(arg1str); + pin_ptr args1Ptr = &bytes_arg1[0]; + session.open(argv[1]); } catch (exception e) @@ -56,33 +62,45 @@ int main(int argc, char* argv[]) try { - if (argc == 3) - { - if (session.catchup_schema(argv[2])) - { - PrintUsage("Catchup schemea success."); - exit(0); - } - else - { - PrintUsage("Chatchup schema failure."); - exit(1); - } - } - else - { - if (session.reload_schema(argv[2], argv[3])) - { - PrintUsage("Catchup schemea success."); - exit(0); - } - else - { - PrintUsage("Chatchup schema failure."); - exit(1); - } + System::String^ arg2str = gcnew System::String(argv[2]); + cli::array^ bytes_arg2 = u8->GetBytes(arg2str); + pin_ptr args2Ptr = &bytes_arg2[0]; + + if (argc == 3) + { + System::String^ tempdir = Path::GetTempPath(); + + cli::array^ bytes_temp = u8->GetBytes(tempdir); + pin_ptr tmpdir_Ptr = &bytes_temp[0]; + + if (session.catchup_schema((const char*)args2Ptr, (const char*)tmpdir_Ptr)) + { + PrintUsage("Catchup schemea success."); + exit(0); + } + else + { + PrintUsage("Chatchup schema failure."); + exit(1); + } + } + else + { + System::String^ arg3str = gcnew System::String(argv[3]); + cli::array^ bytes_arg3 = u8->GetBytes(arg3str); + pin_ptr args3Ptr = &bytes_arg3[0]; - } + if (session.reload_schema((const char*)args2Ptr, (const char*)args3Ptr)) + { + PrintUsage("Catchup schemea success."); + exit(0); + } + else + { + PrintUsage("Chatchup schema failure."); + exit(1); + } + } } catch (exception e) {