--- a/src/SqlHandler.h Tue Oct 22 16:05:36 2019 +0200
+++ b/src/SqlHandler.h Fri Oct 25 12:33:00 2019 +0200
@@ -19,6 +19,7 @@
#include <memory>
#include <string>
#include <sstream>
+#include <regex>
#include <vector>
#include <locale>
#include <codecvt>
@@ -170,6 +171,29 @@
}
}
+ std::vector<string_t> getAllRelations() {
+ std::vector<string_t> relations;
+ std::unique_ptr<PreparedStatement> prepared(connection->prepareStatement("SELECT name FROM sqlite_master WHERE type IN ('table', 'view')"));
+ while (prepared->next()) relations.push_back(convertor.from_bytes(prepared->getString(0)));
+ return relations;
+ }
+
+ void dumpRelations() {
+ std::wregex pattern(configuration.dumpRelations);
+ for (string_t relation : getAllRelations()) {
+ if (regex_match(relation, pattern)) {
+ std::wstringstream select;
+ select << L"SELECT * FROM ";
+ writeIdentifier(select, relation);
+
+ Statement statement;
+ statement.relation = relation;
+ statement.sql = select.str();
+ processStatement(statement);
+ }
+ }
+ }
+
relpipe::writer::string_t toSQLType(relpipe::reader::TypeId typeId) {
if (typeId == relpipe::reader::TypeId::BOOLEAN) return L"integer"; // TODO: map selected values back to booleans or allow optional storage as string
else if (typeId == relpipe::reader::TypeId::INTEGER) return L"integer";
@@ -279,6 +303,9 @@
// run the transformation – process all statements:
for (const Statement& statement : configuration.statements) processStatement(statement);
+ // pass-through some relations:
+ if (configuration.dumpRelations.size()) dumpRelations();
+
// delete or keep the file:
if (configuration.file.size()) {
if (configuration.keepFile == KeepFile::Never || (configuration.keepFile == KeepFile::Automatic && !fileAlreadyExisted)) {