src/StreamRelationalWriter.h
branchv_0
changeset 27 a64afb2d24c9
parent 26 8ae93a43fed2
child 29 142bdbba520f
equal deleted inserted replaced
26:8ae93a43fed2 27:a64afb2d24c9
     7 #include <relpipe/protocol/constants.h>
     7 #include <relpipe/protocol/constants.h>
     8 
     8 
     9 #include "../include/relpipe/writer/typedefs.h"
     9 #include "../include/relpipe/writer/typedefs.h"
    10 #include "../include/relpipe/writer/RelationalWriter.h"
    10 #include "../include/relpipe/writer/RelationalWriter.h"
    11 #include "../include/relpipe/writer/TypeId.h"
    11 #include "../include/relpipe/writer/TypeId.h"
       
    12 #include "../include/relpipe/writer/AttributeMetadata.h"
    12 #include "DataTypeWriterBase.h"
    13 #include "DataTypeWriterBase.h"
    13 #include "types/BooleanDataTypeWriter.h"
    14 #include "types/BooleanDataTypeWriter.h"
    14 #include "types/IntegerDataTypeWriter.h"
    15 #include "types/IntegerDataTypeWriter.h"
    15 #include "types/StringDataTypeWriter.h"
    16 #include "types/StringDataTypeWriter.h"
    16 
    17 
    60 	TypeId toTypeId(const string_t typeCode) override {
    61 	TypeId toTypeId(const string_t typeCode) override {
    61 		for (DataTypeWriterBase* writer : writers) if (writer->supports(typeCode)) return writer->getTypeId();
    62 		for (DataTypeWriterBase* writer : writers) if (writer->supports(typeCode)) return writer->getTypeId();
    62 		throw RelpipeWriterException(L"Unsupported data type: " + typeCode);
    63 		throw RelpipeWriterException(L"Unsupported data type: " + typeCode);
    63 	}
    64 	}
    64 
    65 
    65 	void startRelation(string_t name, std::vector<std::pair<string_t, TypeId> > attributes, boolean_t writeHeader) override {
    66 	void startRelation(string_t name, std::vector<AttributeMetadata> attributes, boolean_t writeHeader) override {
    66 		string_t tableName = name;
    67 		string_t tableName = name;
    67 		columnCount = attributes.size();
    68 		columnCount = attributes.size();
    68 		currentColumn = 0;
    69 		currentColumn = 0;
    69 
    70 
    70 		// Write table name and column count:
    71 		// Write table name and column count:
    75 		columnTypes.clear();
    76 		columnTypes.clear();
    76 		columnTypes.resize(columnCount);
    77 		columnTypes.resize(columnCount);
    77 
    78 
    78 		// Write column names:
    79 		// Write column names:
    79 		for (size_t c = 0; c < columnCount; c++) {
    80 		for (size_t c = 0; c < columnCount; c++) {
    80 			wstring columnName = attributes[c].first;
    81 			wstring columnName = attributes[c].attributeName;
    81 			stringWriter.writeValue(output, columnName);
    82 			stringWriter.writeValue(output, columnName);
    82 		}
    83 		}
    83 
    84 
    84 		// Write column types:
    85 		// Write column types:
    85 		for (size_t c = 0; c < columnCount; c++) {
    86 		for (size_t c = 0; c < columnCount; c++) {
    86 			TypeId typeId = attributes[c].second;
    87 			TypeId typeId = attributes[c].typeId;
    87 			integerWriter.writeValue(output, static_cast<integer_t> (typeId));
    88 			integerWriter.writeValue(output, static_cast<integer_t> (typeId));
    88 			columnTypes[c] = typeId;
    89 			columnTypes[c] = typeId;
    89 		}
    90 		}
    90 
    91 
    91 	}
    92 	}