equal
deleted
inserted
replaced
37 #include "Configuration.h" |
37 #include "Configuration.h" |
38 #include "SqlException.h" |
38 #include "SqlException.h" |
39 #include "SqlInputScanner.h" |
39 #include "SqlInputScanner.h" |
40 #include "PreparedStatement.h" |
40 #include "PreparedStatement.h" |
41 #include "Connection.h" |
41 #include "Connection.h" |
|
42 #include "DriverManager.h" |
42 |
43 |
43 namespace relpipe { |
44 namespace relpipe { |
44 namespace tr { |
45 namespace tr { |
45 namespace sql { |
46 namespace sql { |
46 |
47 |
52 class SqlHandler : public RelationalReaderValueHandler { |
53 class SqlHandler : public RelationalReaderValueHandler { |
53 private: |
54 private: |
54 Configuration configuration; |
55 Configuration configuration; |
55 boolean_t fileAlreadyExisted = false; |
56 boolean_t fileAlreadyExisted = false; |
56 writer::RelationalWriter* relationalWriter; |
57 writer::RelationalWriter* relationalWriter; |
|
58 DriverManager* driverManager; |
57 std::wstring_convert<codecvt_utf8<wchar_t>> convertor; // TODO: support also other encodings |
59 std::wstring_convert<codecvt_utf8<wchar_t>> convertor; // TODO: support also other encodings |
58 vector<AttributeMetadata> currentReaderMetadata; |
60 vector<AttributeMetadata> currentReaderMetadata; |
59 integer_t currentAttributeIndex = 0; |
61 integer_t currentAttributeIndex = 0; |
60 std::unique_ptr<Connection> connection; |
62 std::unique_ptr<Connection> connection; |
61 std::unique_ptr<PreparedStatement> currentInsert; |
63 std::unique_ptr<PreparedStatement> currentInsert; |
154 output << L'"'; |
156 output << L'"'; |
155 } |
157 } |
156 |
158 |
157 public: |
159 public: |
158 |
160 |
159 SqlHandler(writer::RelationalWriter* relationalWriter, Configuration& configuration) : relationalWriter(relationalWriter), configuration(configuration) { |
161 SqlHandler(writer::RelationalWriter* relationalWriter, DriverManager* driverManager, Configuration& configuration) : relationalWriter(relationalWriter), driverManager(driverManager), configuration(configuration) { |
160 std::string file; |
162 std::string file; |
161 if (configuration.file.size()) { |
163 if (configuration.file.size()) { |
162 file = convertor.to_bytes(configuration.file); |
164 file = convertor.to_bytes(configuration.file); |
163 |
165 |
164 // in C++17 we can use: std::filesystem::exists() |
166 // in C++17 we can use: std::filesystem::exists() |
268 if (result) throw SqlException(L"Unable to delete SQLite file."); |
270 if (result) throw SqlException(L"Unable to delete SQLite file."); |
269 } |
271 } |
270 } // else: we had no file, everything was in memory |
272 } // else: we had no file, everything was in memory |
271 } |
273 } |
272 |
274 |
|
275 static void listDataSources(writer::RelationalWriter* relationalWriter, DriverManager* driverManager) { |
|
276 relationalWriter->startRelation(L"data_source",{ |
|
277 {L"name", writer::TypeId::STRING}, |
|
278 {L"description", writer::TypeId::STRING} |
|
279 }, true); |
|
280 |
|
281 for (DriverManager::DataSource ds : driverManager->getDataSources()) { |
|
282 relationalWriter->writeAttribute(ds.name); |
|
283 relationalWriter->writeAttribute(ds.description); |
|
284 } |
|
285 } |
|
286 |
273 }; |
287 }; |
274 |
288 |
275 } |
289 } |
276 } |
290 } |
277 } |
291 } |