equal
deleted
inserted
replaced
|
1 #pragma once |
|
2 |
|
3 #include <cstdlib> |
|
4 #include <iostream> |
|
5 #include <string> |
|
6 #include <vector> |
|
7 #include <algorithm> |
|
8 |
|
9 #include <typedefs.h> |
|
10 |
|
11 #include "Command.h" |
|
12 |
|
13 namespace relpipe { |
|
14 namespace in { |
|
15 namespace cli { |
|
16 |
|
17 class ArgumentsCommand : public Command { |
|
18 public: |
|
19 |
|
20 void process(std::istream& input, std::ostream& output, const relpipe::writer::string_t& command, const std::vector<relpipe::writer::string_t>& arguments) override { |
|
21 using namespace relpipe::writer; |
|
22 |
|
23 size_t i = 0; |
|
24 string_t relationName = arguments[i++]; |
|
25 integer_t attributeCount = std::stoul(arguments[i++]); // TODO: use integer data type's method? |
|
26 boolean_t writeHeader = true; // TODO: add option for header omitting |
|
27 |
|
28 // TODO: check argument count |
|
29 |
|
30 std::shared_ptr<RelationalWriter> writer(Factory::create(output)); |
|
31 |
|
32 std::vector<std::pair<string_t, TypeId >> attributes(attributeCount); |
|
33 |
|
34 for (size_t j = 0; j < attributeCount; j++) { |
|
35 string_t attributeName = arguments[i++]; |
|
36 TypeId attributeType = writer->toTypeId(arguments[i++]); |
|
37 attributes[j] = {attributeName, attributeType}; |
|
38 } |
|
39 |
|
40 writer->startRelation(relationName, attributes, writeHeader); |
|
41 |
|
42 for (; i < arguments.size(); i++) { |
|
43 writer->writeAttribute(arguments[i]); |
|
44 } |
|
45 } |
|
46 }; |
|
47 |
|
48 } |
|
49 } |
|
50 } |