|
CuteHMI - Data Acquisition (CuteHMI.DataAcquisition.0)
|
1 #ifndef H_EXTENSIONS_CUTEHMI_DATAACQUISITION_0_INCLUDE_CUTEHMI_DATAACQUISITION_INTERNAL_RECENCYTABLE_HPP
2 #define H_EXTENSIONS_CUTEHMI_DATAACQUISITION_0_INCLUDE_CUTEHMI_DATAACQUISITION_INTERNAL_RECENCYTABLE_HPP
5 #include "TableObject.hpp"
6 #include "TagCache.hpp"
7 #include "TableNameTraits.hpp"
14 namespace dataacquisition {
70 worker([
this, columnValues, tableName](
QSqlDatabase & db) {
73 CUTEHMI_DEBUG(
"Storing '" << tableName <<
"' values...");
75 for (QStringList::const_iterator tagName = columnValues.tagName.begin(); tagName != columnValues.tagName.end(); ++tagName)
76 tagIds.append(tagCache()->getId(*tagName, db));
78 query.prepare(QString(
"INSERT INTO %1.%2 (tag_id, value, time) VALUES (:tagId, :value, :time)"
79 " ON CONFLICT (tag_id) DO UPDATE SET(value, time) = (:value, :time) WHERE %1.%2.tag_id = :tagId").arg(schema()->name()).arg(tableName));
80 query.bindValue(
":tagId", tagIds);
81 query.bindValue(
":value", columnValues.value);
82 query.bindValue(
":time", columnValues.time);
85 pushError(query.lastError());
89 CUTEHMI_DEBUG(
"Storing '" << tableName <<
"' values...");
91 for (QStringList::const_iterator tagName = columnValues.tagName.begin(); tagName != columnValues.tagName.end(); ++tagName)
92 tagIds.append(tagCache()->getId(*tagName, db));
94 query.prepare(QString(
"INSERT INTO [%1.%2] (tag_id, value, time) VALUES (:tagId, :value, :time)"
95 " ON CONFLICT (tag_id) DO UPDATE SET(value, time) = (:value, :time)").arg(schema()->name()).arg(tableName));
96 query.bindValue(
":tagId", tagIds);
97 query.bindValue(
":value", columnValues.value);
98 query.bindValue(
":time", columnValues.time);
101 pushError(query.lastError());
104 emit errored(CUTEHMI_ERROR(tr(
"Driver '%1' is not supported.").arg(db.
driverName())));
108 template <
typename T>
113 value.append(it->value);
114 time.append(it->time);
118 template <
typename T>
void append(const T &value)
static QString Affixed(const QString &name)
Definition: TagCache.hpp:13
QVariantList time
Definition: RecencyTable.hpp:41
Definition: RecencyTable.hpp:24
TagCache * tagCache() const
Definition: RecencyTable.hpp:119
void update(const TuplesContainer &tuples)
Definition: RecencyTable.hpp:65
Definition: TableObject.hpp:13
RecencyTable(TagCache *tagCache, Schema *schema, QObject *parent=nullptr)
Definition: RecencyTable.hpp:58
QDateTime time
Definition: RecencyTable.hpp:27
QHash< QString, Tuple > TuplesContainer
Definition: RecencyTable.hpp:30
Definition: RecencyTable.hpp:18
Schema schema
Definition: TableObject.hpp:22
QStringList tagName
Definition: RecencyTable.hpp:39
ColumnValues(const TuplesContainer &tuples)
Definition: RecencyTable.hpp:109
Database schema.
Definition: Schema.hpp:13
T value
Definition: RecencyTable.hpp:26
Definition: RecencyTable.hpp:37
T type
Definition: RecencyTable.hpp:22
QString driverName() const const
QVariantList value
Definition: RecencyTable.hpp:40
QObject * parent() const const