34 #include <relpipe/writer/TypeId.h> |
34 #include <relpipe/writer/TypeId.h> |
35 |
35 |
36 #include "SqlHandler.h" |
36 #include "SqlHandler.h" |
37 #include "CLIParser.h" |
37 #include "CLIParser.h" |
38 #include "Configuration.h" |
38 #include "Configuration.h" |
|
39 #include "DriverManager.h" |
39 |
40 |
40 using namespace relpipe::cli; |
41 using namespace relpipe::cli; |
41 using namespace relpipe::reader; |
42 using namespace relpipe::reader; |
42 using namespace relpipe::tr::sql; |
43 using namespace relpipe::tr::sql; |
43 |
44 |
50 |
51 |
51 try { |
52 try { |
52 CLIParser cliParser; |
53 CLIParser cliParser; |
53 Configuration configuration = cliParser.parse(cli.arguments()); |
54 Configuration configuration = cliParser.parse(cli.arguments()); |
54 |
55 |
55 if (std::regex_match(cli.programName(), std::wregex(L"^(.*/)?relpipe-in-sql$"))) { |
56 std::shared_ptr<DriverManager> driverManager = std::make_shared<DriverManager>(); |
|
57 std::shared_ptr<writer::RelationalWriter> writer(writer::Factory::create(std::cout)); |
|
58 |
|
59 if (configuration.listDataSources) { |
|
60 // --list-data-sources: |
|
61 SqlHandler::listDataSources(writer.get(), driverManager.get()); |
|
62 } else if (std::regex_match(cli.programName(), std::wregex(L"^(.*/)?relpipe-in-sql$"))) { |
56 // relpipe-in-sql: |
63 // relpipe-in-sql: |
57 if (cli.arguments().size() == 0) configuration.copyRelations.push_back({L".*", L"", false}); |
64 if (cli.arguments().size() == 0) configuration.copyRelations.push_back({L".*", L"", false}); |
58 std::shared_ptr<writer::RelationalWriter> writer(writer::Factory::create(std::cout)); |
|
59 configuration.sqlBeforeRelational = isatty(fileno(stdin)) ? nullptr : &std::wcin; |
65 configuration.sqlBeforeRelational = isatty(fileno(stdin)) ? nullptr : &std::wcin; |
60 configuration.sqlAfterRelational = nullptr; |
66 configuration.sqlAfterRelational = nullptr; |
61 SqlHandler handler(writer.get(), configuration); |
67 SqlHandler handler(writer.get(), driverManager.get(), configuration); |
62 handler.endOfPipe(); |
68 handler.endOfPipe(); |
63 } else { |
69 } else { |
64 // relpipe-tr-sql: |
70 // relpipe-tr-sql: |
65 std::shared_ptr<reader::RelationalReader> reader(reader::Factory::create(std::cin)); |
71 std::shared_ptr<reader::RelationalReader> reader(reader::Factory::create(std::cin)); |
66 std::shared_ptr<writer::RelationalWriter> writer(writer::Factory::create(std::cout)); |
72 SqlHandler handler(writer.get(), driverManager.get(), configuration); |
67 SqlHandler handler(writer.get(), configuration); |
|
68 reader->addHandler(&handler); |
73 reader->addHandler(&handler); |
69 reader->process(); |
74 reader->process(); |
70 } |
75 } |
71 |
76 |
72 resultCode = CLI::EXIT_CODE_SUCCESS; |
77 resultCode = CLI::EXIT_CODE_SUCCESS; |