summaryrefslogtreecommitdiffstats
path: root/tests/hawd/dataset.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/hawd/dataset.cpp')
-rw-r--r--tests/hawd/dataset.cpp40
1 files changed, 30 insertions, 10 deletions
diff --git a/tests/hawd/dataset.cpp b/tests/hawd/dataset.cpp
index 6fc85ce..592612e 100644
--- a/tests/hawd/dataset.cpp
+++ b/tests/hawd/dataset.cpp
@@ -34,6 +34,8 @@ Dataset::Row::Row(const Row &other)
34 : m_key(other.m_key), 34 : m_key(other.m_key),
35 m_columns(other.m_columns), 35 m_columns(other.m_columns),
36 m_data(other.m_data), 36 m_data(other.m_data),
37 m_annotation(other.m_annotation),
38 m_commitHash(other.m_commitHash),
37 m_dataset(other.m_dataset) 39 m_dataset(other.m_dataset)
38{ 40{
39} 41}
@@ -57,6 +59,8 @@ Dataset::Row &Dataset::Row::operator=(const Row &rhs)
57 m_columns = rhs.m_columns; 59 m_columns = rhs.m_columns;
58 m_data = rhs.m_data; 60 m_data = rhs.m_data;
59 m_dataset = rhs.m_dataset; 61 m_dataset = rhs.m_dataset;
62 m_annotation = rhs.m_annotation;
63 m_commitHash = rhs.m_commitHash;
60 return *this; 64 return *this;
61} 65}
62 66
@@ -74,6 +78,11 @@ void Dataset::Row::annotate(const QString &note)
74 m_annotation = note; 78 m_annotation = note;
75} 79}
76 80
81void Dataset::Row::setCommitHash(const QString &hash)
82{
83 m_commitHash = hash;
84}
85
77qint64 Dataset::Row::key() const 86qint64 Dataset::Row::key() const
78{ 87{
79 if (m_key < 1) { 88 if (m_key < 1) {
@@ -90,11 +99,16 @@ void Dataset::Row::fromBinary(QByteArray &data)
90 QDataStream stream(&data, QIODevice::ReadOnly); 99 QDataStream stream(&data, QIODevice::ReadOnly);
91 100
92 while (!stream.atEnd()) { 101 while (!stream.atEnd()) {
93 stream >> key >> value; 102 stream >> key;
103 if (stream.atEnd()) {
104 break;
105 }
106
107 stream >> value;
94 if (key == s_annotationKey) { 108 if (key == s_annotationKey) {
95 m_annotation = value.toString(); 109 m_annotation = value.toString();
96 } else if (key == s_hashKey) { 110 } else if (key == s_hashKey) {
97 m_hash = value.toString(); 111 m_commitHash = value.toString();
98 } else { 112 } else {
99 setValue(key, value); 113 setValue(key, value);
100 } 114 }
@@ -105,19 +119,23 @@ QByteArray Dataset::Row::toBinary() const
105{ 119{
106 QByteArray data; 120 QByteArray data;
107 QDataStream stream(&data, QIODevice::WriteOnly); 121 QDataStream stream(&data, QIODevice::WriteOnly);
122
108 QHashIterator<QString, QVariant> it(m_data); 123 QHashIterator<QString, QVariant> it(m_data);
109 while (it.hasNext()) { 124 while (it.hasNext()) {
110 it.next(); 125 it.next();
111 stream << it.key() << it.value(); 126 if (it.value().isValid()) {
127 stream << it.key() << it.value();
128 }
112 } 129 }
113 130
114 if (!m_hash.isEmpty()) { 131 if (!m_commitHash.isEmpty()) {
115 stream << s_hashKey << m_hash; 132 stream << s_hashKey << QVariant(m_commitHash);
116 } 133 }
117 134
118 if (!m_annotation.isEmpty()) { 135 if (!m_annotation.isEmpty()) {
119 stream << s_annotationKey << m_annotation; 136 stream << s_annotationKey << QVariant(m_annotation);
120 } 137 }
138
121 return data; 139 return data;
122} 140}
123 141
@@ -169,7 +187,7 @@ QString Dataset::Row::toString(const QStringList &cols, int standardCols, const
169 } 187 }
170 188
171 if (standardCols & CommitHash) { 189 if (standardCols & CommitHash) {
172 strings << m_hash; 190 strings << m_commitHash;
173 } 191 }
174 192
175 QHashIterator<QString, QVariant> it(m_data); 193 QHashIterator<QString, QVariant> it(m_data);
@@ -189,9 +207,9 @@ QString Dataset::Row::toString(const QStringList &cols, int standardCols, const
189 207
190Dataset::Dataset(const QString &name, const State &state) 208Dataset::Dataset(const QString &name, const State &state)
191 : m_definition(state.datasetDefinition(name)), 209 : m_definition(state.datasetDefinition(name)),
192 m_storage(state.resultsPath(), name, Storage::ReadWrite) 210 m_storage(state.resultsPath(), name, Storage::ReadWrite),
211 m_commitHash(state.commitHash())
193{ 212{
194 //TODO: it should use a different file name if the data columns have changed
195 m_storage.startTransaction(); 213 m_storage.startTransaction();
196} 214}
197 215
@@ -252,7 +270,9 @@ void Dataset::eachRow(const std::function<void(const Row &row)> &resultHandler)
252Dataset::Row Dataset::row(qint64 key) 270Dataset::Row Dataset::row(qint64 key)
253{ 271{
254 if (key < 1) { 272 if (key < 1) {
255 return Row(*this); 273 Row row(*this);
274 row.setCommitHash(m_commitHash);
275 return row;
256 } 276 }
257 277
258 Row row(*this, key); 278 Row row(*this, key);