--- a/src/CSVCommand.cpp Sun Apr 18 18:20:09 2021 +0200
+++ b/src/CSVCommand.cpp Sat Nov 13 11:52:54 2021 +0100
@@ -134,12 +134,14 @@
vector<AttributeMetadata> metadata;
bool headerDone = false;
bool lastInRecord = false;
+ integer_t valueCount = 0;
stringstream currentValue;
while (readValue(input, currentValue, lastInRecord) && input.good()) {
if (headerDone) {
writer->writeAttribute(convertor.from_bytes(currentValue.str()));
+ valueCount++;
} else {
AttributeMetadata am;
am.attributeName = convertor.from_bytes(currentValue.str());
@@ -173,6 +175,13 @@
currentValue.str("");
currentValue.clear();
}
+
+ /**
+ * RFC 4180:
+ * - Each line should contain the same number of fields throughout the file.
+ * - The last field in the record must not be followed by a comma.
+ */
+ if (valueCount % metadata.size()) throw RelpipeWriterException(L"The total number of values " + std::to_wstring(valueCount) + L" does not match the number of declared columns " + std::to_wstring(metadata.size()));
}
}