From 15f3eaa02e5cdbffe884d51bb5189cc4316b67c3 Mon Sep 17 00:00:00 2001 From: stephb9959 Date: Thu, 4 Jan 2024 13:04:25 -0800 Subject: [PATCH] https://telecominfraproject.atlassian.net/browse/WIFI-13268 Signed-off-by: stephb9959 --- src/StorageService.h | 6 +++--- src/storage/storage_device.cpp | 13 +++++-------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/StorageService.h b/src/StorageService.h index cd03df24..7d2ef093 100644 --- a/src/StorageService.h +++ b/src/StorageService.h @@ -143,9 +143,9 @@ namespace OpenWifi { bool simulated); bool CreateDevice(Poco::Data::Session &Sess, GWObjects::Device &DeviceDetails); - bool GetDevice(LockedDbSession &Session, std::string &SerialNumber, GWObjects::Device &); - bool GetDevice(Poco::Data::Session &Session, std::string &SerialNumber, GWObjects::Device &DeviceDetails); - bool GetDevice(std::string &SerialNumber, GWObjects::Device &); + bool GetDevice(LockedDbSession &Session, const std::string &SerialNumber, GWObjects::Device &); + bool GetDevice(Poco::Data::Session &Session, const std::string &SerialNumber, GWObjects::Device &DeviceDetails); + bool GetDevice(const std::string &SerialNumber, GWObjects::Device &); bool GetDevices(uint64_t From, uint64_t HowMany, std::vector &Devices, const std::string &orderBy = ""); // bool GetDevices(uint64_t From, uint64_t HowMany, const std::string & Select, diff --git a/src/storage/storage_device.cpp b/src/storage/storage_device.cpp index 7c9185ae..5aafe0a5 100644 --- a/src/storage/storage_device.cpp +++ b/src/storage/storage_device.cpp @@ -708,17 +708,14 @@ namespace OpenWifi { return false; } - bool Storage::GetDevice(Poco::Data::Session &Session, std::string &SerialNumber, GWObjects::Device &DeviceDetails) { + bool Storage::GetDevice(Poco::Data::Session &Session, const std::string &SerialNumber, GWObjects::Device &DeviceDetails) { try { Poco::Data::Statement Select(Session); - std::string St{"SELECT " + DB_DeviceSelectFields + - " FROM Devices WHERE SerialNumber=?"}; + std::string St = fmt::format("SELECT {} FROM Devices WHERE SerialNumber='{}'", DB_DeviceSelectFields, SerialNumber); DeviceRecordTuple R; - Select << ConvertParams(St), Poco::Data::Keywords::into(R), - Poco::Data::Keywords::use(SerialNumber); + Select << St, Poco::Data::Keywords::into(R); Select.execute(); - if (Select.rowsExtracted() == 0) return false; ConvertDeviceRecord(R, DeviceDetails); @@ -729,7 +726,7 @@ namespace OpenWifi { return false; } - bool Storage::GetDevice(std::string &SerialNumber, GWObjects::Device &DeviceDetails) { + bool Storage::GetDevice(const std::string &SerialNumber, GWObjects::Device &DeviceDetails) { try { auto Sess = Pool_->get(); return GetDevice(Sess, SerialNumber, DeviceDetails); @@ -739,7 +736,7 @@ namespace OpenWifi { return false; } - bool Storage::GetDevice(LockedDbSession &Session, std::string &SerialNumber, GWObjects::Device &DeviceDetails) { + bool Storage::GetDevice(LockedDbSession &Session, const std::string &SerialNumber, GWObjects::Device &DeviceDetails) { try { std::lock_guard Lock(Session.Mutex()); return GetDevice(Session.Session(), SerialNumber, DeviceDetails);