diff options
author | Jacob Keeler <jacob.keeler@livioradio.com> | 2021-05-20 17:13:45 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-20 17:13:45 -0400 |
commit | b212a12f90934e2c32603c922538acbacbb5bb6d (patch) | |
tree | eaa55d5c704bf500c5c7caf251b3fe1833dc1726 | |
parent | 03c951b5f76cbc855e2ebbc412307ce4de446b92 (diff) | |
download | sdl_core-b212a12f90934e2c32603c922538acbacbb5bb6d.tar.gz |
Fix saving to endpoint properties table (#3704)
`EndpointProperty.version` is defined as an optional value, but was being used as a mandatory one. Also makes `service` property unique in `endpoint_properties` to prevent duplicate entries
4 files changed, 22 insertions, 10 deletions
diff --git a/src/components/policy/policy_external/src/sql_pt_queries.cc b/src/components/policy/policy_external/src/sql_pt_queries.cc index 519e51dde5..c5fc3a9e92 100644 --- a/src/components/policy/policy_external/src/sql_pt_queries.cc +++ b/src/components/policy/policy_external/src/sql_pt_queries.cc @@ -400,8 +400,8 @@ const std::string kCreateSchema = " ON `endpoint`(`application_id` COLLATE NOCASE); " /*endpoint properties*/ "CREATE TABLE IF NOT EXISTS `endpoint_properties`( " - " `service` VARCHAR(100) NOT NULL, " - " `version` VARCHAR(100) NOT NULL " + " `service` VARCHAR(100) PRIMARY KEY NOT NULL, " + " `version` VARCHAR(100) " ");" "CREATE TABLE IF NOT EXISTS `message`( " " `id` INTEGER PRIMARY KEY NOT NULL, " diff --git a/src/components/policy/policy_external/src/sql_pt_representation.cc b/src/components/policy/policy_external/src/sql_pt_representation.cc index d4458ef2a5..3309893db0 100644 --- a/src/components/policy/policy_external/src/sql_pt_representation.cc +++ b/src/components/policy/policy_external/src/sql_pt_representation.cc @@ -530,9 +530,13 @@ void SQLPTRepresentation::GatherModuleConfig( } else { while (endpoint_properties.Next()) { const std::string& service = endpoint_properties.GetString(0); - const std::string& version = endpoint_properties.GetString(1); auto& ep_properties = (*config->endpoint_properties); - *ep_properties[service].version = version; + if (!endpoint_properties.IsNull(1)) { + const std::string& version = endpoint_properties.GetString(1); + *ep_properties[service].version = version; + } else { + ep_properties[service].version = rpc::Optional<rpc::String<0, 100> >(); + } } } @@ -1581,7 +1585,9 @@ bool SQLPTRepresentation::SaveServiceEndpointProperties( for (auto& endpoint_property : endpoint_properties) { query.Bind(0, endpoint_property.first); - query.Bind(1, endpoint_property.second.version); + endpoint_property.second.version.is_initialized() + ? query.Bind(1, *endpoint_property.second.version) + : query.Bind(1); if (!query.Exec() || !query.Reset()) { SDL_LOG_WARN( diff --git a/src/components/policy/policy_regular/src/sql_pt_queries.cc b/src/components/policy/policy_regular/src/sql_pt_queries.cc index ea0b7fe997..a58867966c 100644 --- a/src/components/policy/policy_regular/src/sql_pt_queries.cc +++ b/src/components/policy/policy_regular/src/sql_pt_queries.cc @@ -371,8 +371,8 @@ const std::string kCreateSchema = /*endpoint properties*/ "CREATE TABLE IF NOT EXISTS `endpoint_properties`( " - " `service` VARCHAR(100) NOT NULL, " - " `version` VARCHAR(100) NOT NULL " + " `service` VARCHAR(100) PRIMARY KEY NOT NULL, " + " `version` VARCHAR(100) " ");" "CREATE TABLE IF NOT EXISTS `message`( " diff --git a/src/components/policy/policy_regular/src/sql_pt_representation.cc b/src/components/policy/policy_regular/src/sql_pt_representation.cc index 57781ae16f..1f24ca9472 100644 --- a/src/components/policy/policy_regular/src/sql_pt_representation.cc +++ b/src/components/policy/policy_regular/src/sql_pt_representation.cc @@ -519,9 +519,13 @@ void SQLPTRepresentation::GatherModuleConfig( } else { while (endpoint_properties.Next()) { const std::string& service = endpoint_properties.GetString(0); - const std::string& version = endpoint_properties.GetString(1); auto& ep_properties = (*config->endpoint_properties); - *ep_properties[service].version = version; + if (!endpoint_properties.IsNull(1)) { + const std::string& version = endpoint_properties.GetString(1); + *ep_properties[service].version = version; + } else { + ep_properties[service].version = rpc::Optional<rpc::String<0, 100> >(); + } } } @@ -1546,7 +1550,9 @@ bool SQLPTRepresentation::SaveServiceEndpointProperties( for (auto& endpoint_property : endpoint_properties) { query.Bind(0, endpoint_property.first); - query.Bind(1, endpoint_property.second.version); + endpoint_property.second.version.is_initialized() + ? query.Bind(1, *endpoint_property.second.version) + : query.Bind(1); if (!query.Exec() || !query.Reset()) { SDL_LOG_WARN( |