--- a/src/CSVCommand.cpp Sat Nov 13 11:52:54 2021 +0100
+++ b/src/CSVCommand.cpp Sat Nov 13 17:05:03 2021 +0100
@@ -141,7 +141,11 @@
while (readValue(input, currentValue, lastInRecord) && input.good()) {
if (headerDone) {
writer->writeAttribute(convertor.from_bytes(currentValue.str()));
+
valueCount++;
+ if (valueCount > metadata.size()) throw RelpipeWriterException(L"The number of values " + std::to_wstring(valueCount) + L" exceeds declared column count: " + std::to_wstring(metadata.size()));
+ if (lastInRecord && valueCount != metadata.size()) throw RelpipeWriterException(L"The number of values " + std::to_wstring(valueCount) + L" is lower than declared column count: " + std::to_wstring(metadata.size()));
+ if (lastInRecord) valueCount = 0;
} else {
AttributeMetadata am;
am.attributeName = convertor.from_bytes(currentValue.str());
@@ -181,7 +185,7 @@
* - 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()));
+ if (valueCount && valueCount != metadata.size()) throw RelpipeWriterException(L"Unexpected EOF: The number of values " + std::to_wstring(valueCount) + L" is lower than declared column count: " + std::to_wstring(metadata.size()));
}
}