src/CSVHandler.h
branchv_0
changeset 14 a7596589a5b0
parent 10 4bcf3fb7cc48
child 17 ea36eed9683f
--- a/src/CSVHandler.h	Sat Jun 06 01:50:44 2020 +0200
+++ b/src/CSVHandler.h	Wed Sep 23 17:17:39 2020 +0200
@@ -29,6 +29,7 @@
 #include <relpipe/reader/handlers/RelationalReaderStringHandler.h>
 #include <relpipe/reader/handlers/AttributeMetadata.h>
 
+#include "Configuration.h"
 #include "RelpipeCSVWriterException.h"
 
 namespace relpipe {
@@ -42,19 +43,20 @@
 class CSVHandler : public RelationalReaderStringHandler {
 private:
 	std::ostream& output;
+	Configuration& configuration;
 	const char QUOTE = '"';
 	std::wstring_convert<std::codecvt_utf8<wchar_t>> convertor; // TODO: local system encoding or generate CSV always in UTF-8 like XML?
 	std::vector<AttributeMetadata> firstAttributes;
 	integer_t valueCount = 0;
 public:
 
-	CSVHandler(std::ostream& output) : output(output) {
+	CSVHandler(std::ostream& output, Configuration& configuration) : output(output), configuration(configuration) {
 	}
 
 	void startRelation(string_t name, std::vector<AttributeMetadata> attributes) override {
 		if (firstAttributes.empty()) {
 			firstAttributes = attributes;
-			for (auto attr : attributes) attribute(attr.getAttributeName());
+			if (configuration.writeHeader) for (auto attr : attributes) attribute(attr.getAttributeName());
 		} else {
 			// TODO: UNION ALL if data types and attribute count matches
 			throw RelpipeCSVWriterException(L"Only a single relation can be converted to the CSV format.");