|
CuteHMI - Data Acquisition (CuteHMI.DataAcquisition.0)
|
1 #ifndef H_EXTENSIONS_CUTEHMI_DATAACQUISITION_0_INCLUDE_CUTEHMI_DATAACQUISITION_INTERNAL_HISTORYTABLE_HPP
2 #define H_EXTENSIONS_CUTEHMI_DATAACQUISITION_0_INCLUDE_CUTEHMI_DATAACQUISITION_INTERNAL_HISTORYTABLE_HPP
5 #include "TableObject.hpp"
6 #include "TagCache.hpp"
7 #include "TableNameTraits.hpp"
14 namespace dataacquisition {
77 ColumnValues columnValues(tuples);
80 worker([
this, columnValues, tableName](
QSqlDatabase & db) {
83 CUTEHMI_DEBUG(
"Storing '" << tableName <<
"' values...");
85 for (QStringList::const_iterator tagName = columnValues.tagName.begin(); tagName != columnValues.tagName.end(); ++tagName)
86 tagIds.append(tagCache()->getId(*tagName, db));
88 query.prepare(QString(
"INSERT INTO %1.%2(tag_id, open, close, min, max, open_time, close_time, count) VALUES (:tagId, :open, :close, :min, :max, :open_time, :close_time, :count)").arg(schema()->name()).arg(tableName));
89 query.bindValue(
":tagId", tagIds);
90 query.bindValue(
":open", columnValues.open);
91 query.bindValue(
":close", columnValues.close);
92 query.bindValue(
":min", columnValues.min);
93 query.bindValue(
":max", columnValues.max);
94 query.bindValue(
":open_time", columnValues.openTime);
95 query.bindValue(
":close_time", columnValues.closeTime);
96 query.bindValue(
":count", columnValues.count);
99 pushError(query.lastError());
103 CUTEHMI_DEBUG(
"Storing '" << tableName <<
"' values...");
105 for (QStringList::const_iterator tagName = columnValues.tagName.begin(); tagName != columnValues.tagName.end(); ++tagName)
106 tagIds.append(tagCache()->getId(*tagName, db));
108 query.prepare(QString(
"INSERT INTO [%1.%2](tag_id, open, close, min, max, open_time, close_time, count) VALUES (:tagId, :open, :close, :min, :max, :open_time, :close_time, :count)").arg(schema()->name()).arg(tableName));
109 query.bindValue(
":tagId", tagIds);
110 query.bindValue(
":open", columnValues.open);
111 query.bindValue(
":close", columnValues.close);
112 query.bindValue(
":min", columnValues.min);
113 query.bindValue(
":max", columnValues.max);
114 query.bindValue(
":open_time", columnValues.openTime);
115 query.bindValue(
":close_time", columnValues.closeTime);
116 query.bindValue(
":count", columnValues.count);
119 pushError(query.lastError());
122 emit errored(CUTEHMI_ERROR(tr(
"Driver '%1' is not supported.").arg(db.
driverName())));
126 template <
typename T>
130 tagName.append(it.key());
131 open.append(it->open);
132 close.append(it->close);
135 openTime.append(it->openTime);
136 closeTime.append(it->closeTime);
137 count.append(it->count);
141 template <
typename T>
HistoryTable(TagCache *tagCache, Schema *schema, QObject *parent=nullptr)
Definition: HistoryTable.hpp:68
QDateTime openTime
Definition: HistoryTable.hpp:30
QHash< QString, Tuple > TuplesContainer
Definition: HistoryTable.hpp:35
TagCache * tagCache() const
Definition: HistoryTable.hpp:142
ColumnValues(const TuplesContainer &tuples)
Definition: HistoryTable.hpp:127
Definition: TagCache.hpp:13
Definition: HistoryTable.hpp:18
QVariantList min
Definition: HistoryTable.hpp:47
QStringList tagName
Definition: HistoryTable.hpp:44
Definition: TableObject.hpp:13
QVariantList open
Definition: HistoryTable.hpp:45
QVariantList close
Definition: HistoryTable.hpp:46
QVariantList closeTime
Definition: HistoryTable.hpp:50
T type
Definition: HistoryTable.hpp:22
Definition: TableNameTraits.hpp:11
T max
Definition: HistoryTable.hpp:29
QVariantList count
Definition: HistoryTable.hpp:51
Schema schema
Definition: TableObject.hpp:22
QVariantList max
Definition: HistoryTable.hpp:48
T min
Definition: HistoryTable.hpp:28
Definition: HistoryTable.hpp:42
QDateTime closeTime
Definition: HistoryTable.hpp:31
Database schema.
Definition: Schema.hpp:13
T open
Definition: HistoryTable.hpp:26
Definition: HistoryTable.hpp:24
void insert(const TuplesContainer &tuples)
Definition: HistoryTable.hpp:75
QString driverName() const const
QObject * parent() const const
QVariantList openTime
Definition: HistoryTable.hpp:49
int count
Definition: HistoryTable.hpp:32
T close
Definition: HistoryTable.hpp:27