|
|
@@ -0,0 +1,46 @@
|
|
|
+#include "DataStorageClient.h"
|
|
|
+#include "DataId.h"
|
|
|
+#include <MySQLClient.h>
|
|
|
+#include <sstream>
|
|
|
+
|
|
|
+
|
|
|
+namespace DataStorage {
|
|
|
+
|
|
|
+DataStorageClient::DataStorageClient(const std::shared_ptr<MySQL::MySQLClient>& pMySQLClient, const std::string& table) :
|
|
|
+ m_pMySQLClient(pMySQLClient),
|
|
|
+ m_table(table)
|
|
|
+{
|
|
|
+}
|
|
|
+
|
|
|
+DataStorageClient::~DataStorageClient()
|
|
|
+{
|
|
|
+}
|
|
|
+
|
|
|
+void DataStorageClient::LogValue(int deviceId, const std::string& dataName, int timestamp, int value)
|
|
|
+{
|
|
|
+ int dataId = DataId(dataName).Id();
|
|
|
+
|
|
|
+ std::stringstream query;
|
|
|
+ query << "INSERT INTO `" << m_table << "` (device_id, data_id, timestamp, value) VALUES (" << deviceId << "," << dataId << ",FROM_UNIXTIME(" << timestamp << ")," << value << ");";
|
|
|
+ m_pMySQLClient->Execute(query.str());
|
|
|
+}
|
|
|
+
|
|
|
+void DataStorageClient::LogValue(int deviceId, const std::string& dataName, int timestamp, double value)
|
|
|
+{
|
|
|
+ int dataId = DataId(dataName).Id();
|
|
|
+
|
|
|
+ std::stringstream query;
|
|
|
+ query << "INSERT INTO `" << m_table << "` (device_id, data_id, timestamp, value) VALUES (" << deviceId << "," << dataId << ",FROM_UNIXTIME(" << timestamp << ")," << value << ");";
|
|
|
+ m_pMySQLClient->Execute(query.str());
|
|
|
+}
|
|
|
+
|
|
|
+void DataStorageClient::LogValue(int deviceId, const std::string& dataName, int timestamp, const std::string& value)
|
|
|
+{
|
|
|
+ int dataId = DataId(dataName).Id();
|
|
|
+
|
|
|
+ std::stringstream query;
|
|
|
+ query << "INSERT INTO `" << m_table << "` (device_id, data_id, timestamp, value) VALUES (" << deviceId << "," << dataId << ",FROM_UNIXTIME(" << timestamp << "),\"" << value << "\");";
|
|
|
+ m_pMySQLClient->Execute(query.str());
|
|
|
+}
|
|
|
+
|
|
|
+} // namespace DataStorageClientImpl
|