src/StreamRelationalWriter.h
branchv_0
changeset 13 e7234dd45166
parent 12 640e88aedf8f
child 14 733334eca89b
equal deleted inserted replaced
12:640e88aedf8f 13:e7234dd45166
     4 #include <iostream>
     4 #include <iostream>
     5 #include <vector>
     5 #include <vector>
     6 
     6 
     7 #include "../include/typedefs.h"
     7 #include "../include/typedefs.h"
     8 #include "../include/RelationalWriter.h"
     8 #include "../include/RelationalWriter.h"
       
     9 #include "../include/TypeId.h"
     9 #include "format.h"
    10 #include "format.h"
    10 #include "DataTypeWriterBase.h"
    11 #include "DataTypeWriterBase.h"
    11 #include "types/BooleanDataTypeWriter.h"
    12 #include "types/BooleanDataTypeWriter.h"
    12 #include "types/IntegerDataTypeWriter.h"
    13 #include "types/IntegerDataTypeWriter.h"
    13 #include "types/StringDataTypeWriter.h"
    14 #include "types/StringDataTypeWriter.h"
    52 	string_t toTypeCode(const integer_t typeId) override {
    53 	string_t toTypeCode(const integer_t typeId) override {
    53 		for (DataTypeWriterBase* writer : writers) if (writer->supports(typeId)) return writer->getTypeCode();
    54 		for (DataTypeWriterBase* writer : writers) if (writer->supports(typeId)) return writer->getTypeCode();
    54 		throw RelpipeWriterException(L"Unsupported data type: " + typeId);
    55 		throw RelpipeWriterException(L"Unsupported data type: " + typeId);
    55 	}
    56 	}
    56 
    57 
    57 	void startRelation(string_t name, std::vector<std::pair<string_t, string_t> > attributes, boolean_t writeHeader) override {
    58 	void startRelation(string_t name, std::vector<std::pair<string_t, TypeId> > attributes, boolean_t writeHeader) override {
    58 		string_t tableName = name;
    59 		string_t tableName = name;
    59 		columnCount = attributes.size();
    60 		columnCount = attributes.size();
    60 
    61 
    61 		// Write table name and column count:
    62 		// Write table name and column count:
    62 		integerWriter.writeValue(output, DATA_PART_START);
    63 		integerWriter.writeValue(output, DATA_PART_START);
    72 			stringWriter.writeValue(output, columnName);
    73 			stringWriter.writeValue(output, columnName);
    73 		}
    74 		}
    74 
    75 
    75 		// Write column types:
    76 		// Write column types:
    76 		for (size_t c = 0; c < columnCount; c++) {
    77 		for (size_t c = 0; c < columnCount; c++) {
    77 			wstring typeCode = attributes[c].second;
    78 			integer_t typeId = static_cast<integer_t>(attributes[c].second);
    78 			integer_t typeId = toTypeId(typeCode);
       
    79 			integerWriter.writeValue(output, typeId);
    79 			integerWriter.writeValue(output, typeId);
    80 			columnTypes[c] = typeId;
    80 			columnTypes[c] = typeId;
    81 		}
    81 		}
    82 
    82 
    83 	}
    83 	}