--- 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;