author | František Kučera <franta-hg@frantovo.cz> |
Sat, 27 Jul 2019 23:51:14 +0200 | |
branch | v_0 |
changeset 1 | eb7134dfdcc5 |
parent 0 | c205f5d06418 |
child 3 | 0b932e05aa9f |
permissions | -rw-r--r-- |
0 | 1 |
/** |
2 |
* Relational pipes |
|
3 |
* Copyright © 2019 František Kučera (Frantovo.cz, GlobalCode.info) |
|
4 |
* |
|
5 |
* This program is free software: you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation, either version 3 of the License, or |
|
8 |
* (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
17 |
*/ |
|
18 |
#pragma once |
|
19 |
||
20 |
#include <memory> |
|
21 |
#include <string> |
|
22 |
#include <vector> |
|
23 |
#include <locale> |
|
24 |
#include <codecvt> |
|
25 |
||
1
eb7134dfdcc5
link to the sqlite3 library
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
26 |
#include <sqlite3.h> |
eb7134dfdcc5
link to the sqlite3 library
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
27 |
|
0 | 28 |
#include <relpipe/reader/typedefs.h> |
29 |
#include <relpipe/reader/TypeId.h> |
|
30 |
#include <relpipe/reader/handlers/RelationalReaderStringHandler.h> |
|
31 |
#include <relpipe/reader/handlers/AttributeMetadata.h> |
|
32 |
||
33 |
#include <relpipe/writer/Factory.h> |
|
34 |
||
35 |
#include "Configuration.h" |
|
36 |
#include "SqlException.h" |
|
37 |
||
38 |
namespace relpipe { |
|
39 |
namespace tr { |
|
40 |
namespace sql { |
|
41 |
||
42 |
using namespace std; |
|
43 |
using namespace relpipe; |
|
44 |
using namespace relpipe::reader; |
|
45 |
using namespace relpipe::reader::handlers; |
|
46 |
||
47 |
class SqlHandler : public RelationalReaderStringHandler { |
|
48 |
private: |
|
49 |
Configuration configuration; |
|
50 |
writer::RelationalWriter* relationalWriter; |
|
51 |
std::wstring_convert<codecvt_utf8<wchar_t>> convertor; // TODO: support also other encodings |
|
1
eb7134dfdcc5
link to the sqlite3 library
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
52 |
sqlite3* db; |
eb7134dfdcc5
link to the sqlite3 library
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
53 |
sqlite3_stmt* currentStatement; |
0 | 54 |
|
55 |
public: |
|
56 |
||
57 |
SqlHandler(writer::RelationalWriter* relationalWriter, Configuration& configuration) : relationalWriter(relationalWriter), configuration(configuration) { |
|
1
eb7134dfdcc5
link to the sqlite3 library
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
58 |
int error = sqlite3_open(":memory:", &db); |
eb7134dfdcc5
link to the sqlite3 library
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
59 |
if (error) { |
eb7134dfdcc5
link to the sqlite3 library
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
60 |
sqlite3_close(db); |
eb7134dfdcc5
link to the sqlite3 library
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
61 |
throw SqlException(L"Unable to open sqlite database."); |
eb7134dfdcc5
link to the sqlite3 library
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
62 |
} |
eb7134dfdcc5
link to the sqlite3 library
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
63 |
} |
eb7134dfdcc5
link to the sqlite3 library
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
64 |
|
eb7134dfdcc5
link to the sqlite3 library
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
65 |
virtual ~SqlHandler() { |
eb7134dfdcc5
link to the sqlite3 library
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
66 |
sqlite3_close(db); |
0 | 67 |
} |
68 |
||
69 |
void startRelation(string_t name, vector<AttributeMetadata> attributes) override { |
|
70 |
||
71 |
} |
|
72 |
||
73 |
void attribute(const string_t& value) override { |
|
74 |
||
75 |
} |
|
76 |
||
77 |
void endOfPipe() { |
|
78 |
||
79 |
} |
|
80 |
||
81 |
}; |
|
82 |
||
83 |
} |
|
84 |
} |
|
85 |
} |