relpipe-in-sql mode: read .sqlite file and generate relational data v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Tue, 22 Oct 2019 16:05:36 +0200
branchv_0
changeset 13 19580b27ade2
parent 12 0b38339b871b
child 14 eacacf060755
relpipe-in-sql mode: read .sqlite file and generate relational data
src/relpipe-tr-sql.cpp
--- a/src/relpipe-tr-sql.cpp	Tue Oct 22 16:04:56 2019 +0200
+++ b/src/relpipe-tr-sql.cpp	Tue Oct 22 16:05:36 2019 +0200
@@ -19,6 +19,7 @@
 #include <cstdlib>
 #include <memory>
 #include <functional>
+#include <regex>
 
 #include <relpipe/cli/CLI.h>
 #include <relpipe/cli/RelpipeCLIException.h>
@@ -50,11 +51,20 @@
 	try {
 		CLIParser cliParser;
 		Configuration configuration = cliParser.parse(cli.arguments());
-		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);
-		reader->addHandler(&handler);
-		reader->process();
+
+		if (std::regex_match(cli.programName(), std::wregex(L"^(.*/)?relpipe-in-sql$"))) {
+			// relpipe-in-sql:
+			std::shared_ptr<writer::RelationalWriter> writer(writer::Factory::create(std::cout));
+			SqlHandler handler(writer.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);
+			reader->addHandler(&handler);
+			reader->process();
+		}
 
 		resultCode = CLI::EXIT_CODE_SUCCESS;