src/relpipe-tr-sql.cpp
branchv_0
changeset 34 24c05e69d68f
parent 19 44db9e1e7c7f
child 35 cd9db43db120
--- a/src/relpipe-tr-sql.cpp	Sat May 23 23:58:50 2020 +0200
+++ b/src/relpipe-tr-sql.cpp	Mon May 25 19:36:06 2020 +0200
@@ -36,6 +36,7 @@
 #include "SqlHandler.h"
 #include "CLIParser.h"
 #include "Configuration.h"
+#include "DriverManager.h"
 
 using namespace relpipe::cli;
 using namespace relpipe::reader;
@@ -52,19 +53,23 @@
 		CLIParser cliParser;
 		Configuration configuration = cliParser.parse(cli.arguments());
 
-		if (std::regex_match(cli.programName(), std::wregex(L"^(.*/)?relpipe-in-sql$"))) {
+		std::shared_ptr<DriverManager> driverManager = std::make_shared<DriverManager>();
+		std::shared_ptr<writer::RelationalWriter> writer(writer::Factory::create(std::cout));
+
+		if (configuration.listDataSources) {
+			// --list-data-sources:
+			SqlHandler::listDataSources(writer.get(), driverManager.get());
+		} else if (std::regex_match(cli.programName(), std::wregex(L"^(.*/)?relpipe-in-sql$"))) {
 			// relpipe-in-sql:
 			if (cli.arguments().size() == 0) configuration.copyRelations.push_back({L".*", L"", false});
-			std::shared_ptr<writer::RelationalWriter> writer(writer::Factory::create(std::cout));
 			configuration.sqlBeforeRelational = isatty(fileno(stdin)) ? nullptr : &std::wcin;
 			configuration.sqlAfterRelational = nullptr;
-			SqlHandler handler(writer.get(), configuration);
+			SqlHandler handler(writer.get(), driverManager.get(), configuration);
 			handler.endOfPipe();
 		} else {
 			// relpipe-tr-sql:
 			std::shared_ptr<reader::RelationalReader> reader(reader::Factory::create(std::cin));
-			std::shared_ptr<writer::RelationalWriter> writer(writer::Factory::create(std::cout));
-			SqlHandler handler(writer.get(), configuration);
+			SqlHandler handler(writer.get(), driverManager.get(), configuration);
 			reader->addHandler(&handler);
 			reader->process();
 		}