src/CSVCommand.cpp
branchv_0
changeset 22 3f6488171e34
parent 21 22eb4838e8d0
equal deleted inserted replaced
21:22eb4838e8d0 22:3f6488171e34
   139 
   139 
   140 
   140 
   141 	while (readValue(input, currentValue, lastInRecord) && input.good()) {
   141 	while (readValue(input, currentValue, lastInRecord) && input.good()) {
   142 		if (headerDone) {
   142 		if (headerDone) {
   143 			writer->writeAttribute(convertor.from_bytes(currentValue.str()));
   143 			writer->writeAttribute(convertor.from_bytes(currentValue.str()));
       
   144 
   144 			valueCount++;
   145 			valueCount++;
       
   146 			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()));
       
   147 			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()));
       
   148 			if (lastInRecord) valueCount = 0;
   145 		} else {
   149 		} else {
   146 			AttributeMetadata am;
   150 			AttributeMetadata am;
   147 			am.attributeName = convertor.from_bytes(currentValue.str());
   151 			am.attributeName = convertor.from_bytes(currentValue.str());
   148 			am.typeId = TypeId::STRING;
   152 			am.typeId = TypeId::STRING;
   149 			metadata.push_back(am);
   153 			metadata.push_back(am);
   179 	/**
   183 	/**
   180 	 * RFC 4180:
   184 	 * RFC 4180:
   181 	 *  - Each line should contain the same number of fields throughout the file.
   185 	 *  - Each line should contain the same number of fields throughout the file.
   182 	 *  - The last field in the record must not be followed by a comma.
   186 	 *  - The last field in the record must not be followed by a comma.
   183 	 */
   187 	 */
   184 	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()));
   188 	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()));
   185 }
   189 }
   186 
   190 
   187 }
   191 }
   188 }
   192 }
   189 }
   193 }