equal
deleted
inserted
replaced
80 } |
80 } |
81 } |
81 } |
82 return false; |
82 return false; |
83 } |
83 } |
84 |
84 |
85 void processDataStream(ostream &output, istream& input) { |
85 void processDataStream(ostream &output, istream& input, const vector<string_t>& args) { |
86 wstring_convert < codecvt_utf8<wchar_t>> convertor; // UTF-8 is required for CSV |
86 wstring_convert < codecvt_utf8<wchar_t>> convertor; // UTF-8 is required for CSV |
87 std::shared_ptr<RelationalWriter> writer(Factory::create(output)); |
87 std::shared_ptr<RelationalWriter> writer(Factory::create(output)); |
88 vector<AttributeMetadata> metadata; |
88 vector<AttributeMetadata> metadata; |
89 bool headerDone = false; |
89 bool headerDone = false; |
90 bool lastInRecord = false; |
90 bool lastInRecord = false; |
99 am.attributeName = convertor.from_bytes(currentValue.str()); |
99 am.attributeName = convertor.from_bytes(currentValue.str()); |
100 am.typeId = TypeId::STRING; // TODO: support also other types passed as CLI parameters |
100 am.typeId = TypeId::STRING; // TODO: support also other types passed as CLI parameters |
101 metadata.push_back(am); |
101 metadata.push_back(am); |
102 if (lastInRecord) { |
102 if (lastInRecord) { |
103 headerDone = true; |
103 headerDone = true; |
104 writer->startRelation(L"csv", metadata, true); // TODO: support also custom relation name passed as CLI parameter |
104 writer->startRelation(args.size() > 0 ? args[0] : L"csv", metadata, true); |
105 } |
105 } |
106 } |
106 } |
107 |
107 |
108 currentValue.str(""); |
108 currentValue.str(""); |
109 currentValue.clear(); |
109 currentValue.clear(); |
116 CLI cli(argc, argv); |
116 CLI cli(argc, argv); |
117 |
117 |
118 int resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR; |
118 int resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR; |
119 |
119 |
120 try { |
120 try { |
121 processDataStream(cout, cin); |
121 processDataStream(cout, cin, cli.arguments()); |
122 resultCode = CLI::EXIT_CODE_SUCCESS; |
122 resultCode = CLI::EXIT_CODE_SUCCESS; |
123 } catch (RelpipeWriterException e) { |
123 } catch (RelpipeWriterException e) { |
124 fwprintf(stderr, L"Caught Writer exception: %ls\n", e.getMessge().c_str()); |
124 fwprintf(stderr, L"Caught Writer exception: %ls\n", e.getMessge().c_str()); |
125 fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount()); |
125 fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount()); |
126 resultCode = CLI::EXIT_CODE_DATA_ERROR; |
126 resultCode = CLI::EXIT_CODE_DATA_ERROR; |