From 8e15a699029f3d6e2e18d45d117a7d4e814a3c3c Mon Sep 17 00:00:00 2001 From: Mykola Korniichuk Date: Thu, 29 Aug 2019 17:26:07 +0300 Subject: Add check for already stored vehicle data item params --- .../policy/policy_external/src/sql_pt_representation.cc | 8 ++++++++ src/components/policy/policy_regular/src/sql_pt_representation.cc | 8 ++++++++ 2 files changed, 16 insertions(+) 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 7874abc4ee..d8f137a52c 100644 --- a/src/components/policy/policy_external/src/sql_pt_representation.cc +++ b/src/components/policy/policy_external/src/sql_pt_representation.cc @@ -2660,11 +2660,18 @@ bool SQLPTRepresentation::InsertVehicleDataItem( } if (vehicle_data_item.params->is_initialized()) { + std::map stored_vehicle_data_item_params; for (const auto& param : *(vehicle_data_item.params)) { if (!InsertVehicleDataItem(param)) { return false; } + if (stored_vehicle_data_item_params.end() != + stored_vehicle_data_item_params.find(param.name)) { + LOG4CXX_DEBUG(logger_, "Parameter already stored."); + continue; + } + if (!query.Prepare(sql_pt::kInsertVehicleDataItemParams)) { LOG4CXX_ERROR(logger_, "Incorrent select statement of vehicle data item. " @@ -2685,6 +2692,7 @@ bool SQLPTRepresentation::InsertVehicleDataItem( << ". Error: " << query.LastError().text()); return false; } + stored_vehicle_data_item_params[param.name] = param.key; } } 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 ce0527600a..60a4ef6021 100644 --- a/src/components/policy/policy_regular/src/sql_pt_representation.cc +++ b/src/components/policy/policy_regular/src/sql_pt_representation.cc @@ -2687,11 +2687,18 @@ bool SQLPTRepresentation::InsertVehicleDataItem( } if (vehicle_data_item.params->is_initialized()) { + std::map stored_vehicle_data_item_params; for (const auto& param : *(vehicle_data_item.params)) { if (!InsertVehicleDataItem(param)) { return false; } + if (stored_vehicle_data_item_params.end() != + stored_vehicle_data_item_params.find(param.name)) { + LOG4CXX_DEBUG(logger_, "Parameter already stored."); + continue; + }; + if (!query.Prepare(sql_pt::kInsertVehicleDataItemParams)) { LOG4CXX_ERROR(logger_, "Incorrent select statement of vehicle data item. " @@ -2712,6 +2719,7 @@ bool SQLPTRepresentation::InsertVehicleDataItem( << ". Error: " << query.LastError().text()); return false; } + stored_vehicle_data_item_params[param.name] = param.key; } } -- cgit v1.2.1