44 bool parseBoolean(const string_t& value) { |
44 bool parseBoolean(const string_t& value) { |
45 if (value == L"true") return true; |
45 if (value == L"true") return true; |
46 else if (value == L"false") return false; |
46 else if (value == L"false") return false; |
47 else throw relpipe::cli::RelpipeCLIException(L"Unable to parse boolean value: " + value + L" (expecting true or false)", relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS); |
47 else throw relpipe::cli::RelpipeCLIException(L"Unable to parse boolean value: " + value + L" (expecting true or false)", relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS); |
48 } |
48 } |
|
49 |
|
50 OnDuplicateRelation parseOnDuplicateRelation(const string_t& value) { |
|
51 if (value == L"insert") return OnDuplicateRelation::Insert; |
|
52 else if (value == L"fail") return OnDuplicateRelation::Fail; |
|
53 else throw relpipe::cli::RelpipeCLIException(L"Unable to parse OnDuplicateRelation value: " + value + L" (expecting fail or insert)", relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS); |
|
54 } |
49 |
55 |
50 void addQuery(Configuration& c, Statement& currentQuery) { |
56 void addQuery(Configuration& c, Statement& currentQuery) { |
51 if (currentQuery.sql.size()) { |
57 if (currentQuery.sql.size()) { |
52 c.statements.push_back(currentQuery); |
58 c.statements.push_back(currentQuery); |
53 currentQuery = Statement(); |
59 currentQuery = Statement(); |
57 public: |
63 public: |
58 |
64 |
59 static const string_t OPTION_RELATION; |
65 static const string_t OPTION_RELATION; |
60 static const string_t OPTION_TYPE_CAST; |
66 static const string_t OPTION_TYPE_CAST; |
61 static const string_t OPTION_PARAMETER; |
67 static const string_t OPTION_PARAMETER; |
|
68 static const string_t OPTION_ON_DUPLICATE_RELATION; |
62 static const string_t OPTION_COPY; |
69 static const string_t OPTION_COPY; |
63 static const string_t OPTION_COPY_RENAMED; |
70 static const string_t OPTION_COPY_RENAMED; |
64 static const string_t OPTION_DATA_SOURCE_NAME; |
71 static const string_t OPTION_DATA_SOURCE_NAME; |
65 static const string_t OPTION_DATA_SOURCE_STRING; |
72 static const string_t OPTION_DATA_SOURCE_STRING; |
66 static const string_t OPTION_LIST_DATA_SOURCES; |
73 static const string_t OPTION_LIST_DATA_SOURCES; |
83 currentQuery.typeCasts.push_back(typeCast); |
90 currentQuery.typeCasts.push_back(typeCast); |
84 } else if (option == OPTION_PARAMETER) { |
91 } else if (option == OPTION_PARAMETER) { |
85 Parameter parameter; |
92 Parameter parameter; |
86 parameter.value = readNext(arguments, i); |
93 parameter.value = readNext(arguments, i); |
87 currentQuery.parameters.push_back(parameter); |
94 currentQuery.parameters.push_back(parameter); |
|
95 } else if (option == OPTION_ON_DUPLICATE_RELATION) { |
|
96 c.onDuplicateRelation = parseOnDuplicateRelation(readNext(arguments, i)); |
88 } else if (option == OPTION_COPY) { |
97 } else if (option == OPTION_COPY) { |
89 c.copyRelations.push_back({readNext(arguments, i), L"", false}); |
98 c.copyRelations.push_back({readNext(arguments, i), L"", false}); |
90 } else if (option == OPTION_COPY_RENAMED) { |
99 } else if (option == OPTION_COPY_RENAMED) { |
91 c.copyRelations.push_back({readNext(arguments, i), readNext(arguments, i), true}); |
100 c.copyRelations.push_back({readNext(arguments, i), readNext(arguments, i), true}); |
92 } else if (option == OPTION_DATA_SOURCE_NAME) { |
101 } else if (option == OPTION_DATA_SOURCE_NAME) { |
113 // TODO: --type string/integer/boolean (default is string) |
122 // TODO: --type string/integer/boolean (default is string) |
114 |
123 |
115 const string_t CLIParser::OPTION_RELATION = L"--relation"; |
124 const string_t CLIParser::OPTION_RELATION = L"--relation"; |
116 const string_t CLIParser::OPTION_TYPE_CAST = L"--type-cast"; |
125 const string_t CLIParser::OPTION_TYPE_CAST = L"--type-cast"; |
117 const string_t CLIParser::OPTION_PARAMETER = L"--parameter"; |
126 const string_t CLIParser::OPTION_PARAMETER = L"--parameter"; |
|
127 const string_t CLIParser::OPTION_ON_DUPLICATE_RELATION = L"--on-duplicate-relation"; |
118 const string_t CLIParser::OPTION_COPY = L"--copy"; |
128 const string_t CLIParser::OPTION_COPY = L"--copy"; |
119 const string_t CLIParser::OPTION_COPY_RENAMED = L"--copy-renamed"; |
129 const string_t CLIParser::OPTION_COPY_RENAMED = L"--copy-renamed"; |
120 const string_t CLIParser::OPTION_LIST_DATA_SOURCES = L"--list-data-sources"; |
130 const string_t CLIParser::OPTION_LIST_DATA_SOURCES = L"--list-data-sources"; |
121 const string_t CLIParser::OPTION_DATA_SOURCE_NAME = L"--data-source-name"; |
131 const string_t CLIParser::OPTION_DATA_SOURCE_NAME = L"--data-source-name"; |
122 const string_t CLIParser::OPTION_DATA_SOURCE_STRING = L"--data-source-string"; |
132 const string_t CLIParser::OPTION_DATA_SOURCE_STRING = L"--data-source-string"; |