# HG changeset patch # User František Kučera # Date 1636819503 -3600 # Node ID 3f6488171e3424790f08de8c8047d943c0e2afea # Parent 22eb4838e8d019c554c779c647da20961f95e821 check number of values on each row diff -r 22eb4838e8d0 -r 3f6488171e34 src/CSVCommand.cpp --- 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())); } }