author | František Kučera <franta-hg@frantovo.cz> |
Thu, 04 Jun 2020 00:46:00 +0200 | |
branch | v_0 |
changeset 47 | 428c278af4be |
parent 37 | 3de41719d7eb |
permissions | -rw-r--r-- |
34
24c05e69d68f
add ODBC library and --list-data-sources mode (DSN)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
1 |
/** |
24c05e69d68f
add ODBC library and --list-data-sources mode (DSN)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
2 |
* Relational pipes |
24c05e69d68f
add ODBC library and --list-data-sources mode (DSN)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
3 |
* Copyright © 2020 František Kučera (Frantovo.cz, GlobalCode.info) |
24c05e69d68f
add ODBC library and --list-data-sources mode (DSN)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
4 |
* |
24c05e69d68f
add ODBC library and --list-data-sources mode (DSN)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
5 |
* This program is free software: you can redistribute it and/or modify |
24c05e69d68f
add ODBC library and --list-data-sources mode (DSN)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
6 |
* it under the terms of the GNU General Public License as published by |
24c05e69d68f
add ODBC library and --list-data-sources mode (DSN)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
7 |
* the Free Software Foundation, version 3. |
24c05e69d68f
add ODBC library and --list-data-sources mode (DSN)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
8 |
* |
24c05e69d68f
add ODBC library and --list-data-sources mode (DSN)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
9 |
* This program is distributed in the hope that it will be useful, |
24c05e69d68f
add ODBC library and --list-data-sources mode (DSN)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
24c05e69d68f
add ODBC library and --list-data-sources mode (DSN)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
24c05e69d68f
add ODBC library and --list-data-sources mode (DSN)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
12 |
* GNU General Public License for more details. |
24c05e69d68f
add ODBC library and --list-data-sources mode (DSN)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
13 |
* |
24c05e69d68f
add ODBC library and --list-data-sources mode (DSN)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License |
24c05e69d68f
add ODBC library and --list-data-sources mode (DSN)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
15 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
24c05e69d68f
add ODBC library and --list-data-sources mode (DSN)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
16 |
*/ |
24c05e69d68f
add ODBC library and --list-data-sources mode (DSN)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
17 |
#pragma once |
24c05e69d68f
add ODBC library and --list-data-sources mode (DSN)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
18 |
|
24c05e69d68f
add ODBC library and --list-data-sources mode (DSN)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
19 |
#include <vector> |
36
91cb012d779a
use ODBC, avoid direct dependency on SQLite
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
20 |
#include <map> |
34
24c05e69d68f
add ODBC library and --list-data-sources mode (DSN)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
21 |
#include <codecvt> |
24c05e69d68f
add ODBC library and --list-data-sources mode (DSN)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
22 |
#include <locale> |
24c05e69d68f
add ODBC library and --list-data-sources mode (DSN)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
23 |
|
24c05e69d68f
add ODBC library and --list-data-sources mode (DSN)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
24 |
#include <relpipe/reader/typedefs.h> |
24c05e69d68f
add ODBC library and --list-data-sources mode (DSN)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
25 |
|
24c05e69d68f
add ODBC library and --list-data-sources mode (DSN)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
26 |
#include "SqlException.h" |
36
91cb012d779a
use ODBC, avoid direct dependency on SQLite
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
27 |
#include "Connection.h" |
34
24c05e69d68f
add ODBC library and --list-data-sources mode (DSN)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
28 |
|
24c05e69d68f
add ODBC library and --list-data-sources mode (DSN)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
29 |
namespace relpipe { |
24c05e69d68f
add ODBC library and --list-data-sources mode (DSN)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
30 |
namespace tr { |
24c05e69d68f
add ODBC library and --list-data-sources mode (DSN)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
31 |
namespace sql { |
24c05e69d68f
add ODBC library and --list-data-sources mode (DSN)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
32 |
|
36
91cb012d779a
use ODBC, avoid direct dependency on SQLite
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
33 |
/** |
91cb012d779a
use ODBC, avoid direct dependency on SQLite
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
34 |
* Common principles in this SQL layer: |
91cb012d779a
use ODBC, avoid direct dependency on SQLite
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
35 |
* - Numbering starts with 1, not 0. First parameter or column = 1. |
91cb012d779a
use ODBC, avoid direct dependency on SQLite
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
36 |
* - If you got a pointer returned from a method or function, you are then responsible for given object. |
91cb012d779a
use ODBC, avoid direct dependency on SQLite
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
37 |
* Wrapping it immediatelly in a smart pointer is a convenient way to manage its lifecycle. |
91cb012d779a
use ODBC, avoid direct dependency on SQLite
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
38 |
* Statements should be destroyed before the Connection. And Connection should be destroyed before DriverManager. |
91cb012d779a
use ODBC, avoid direct dependency on SQLite
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
39 |
*/ |
34
24c05e69d68f
add ODBC library and --list-data-sources mode (DSN)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
40 |
class DriverManager { |
24c05e69d68f
add ODBC library and --list-data-sources mode (DSN)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
41 |
private: |
37
3de41719d7eb
add options --data-source-name and --data-source-url for custom datasource; drop options --file and --file-keep
František Kučera <franta-hg@frantovo.cz>
parents:
36
diff
changeset
|
42 |
void* environment; |
34
24c05e69d68f
add ODBC library and --list-data-sources mode (DSN)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
43 |
std::wstring_convert<std::codecvt_utf8<wchar_t>> convertor; // TODO: support also other encodings |
24c05e69d68f
add ODBC library and --list-data-sources mode (DSN)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
44 |
|
24c05e69d68f
add ODBC library and --list-data-sources mode (DSN)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
45 |
public: |
24c05e69d68f
add ODBC library and --list-data-sources mode (DSN)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
46 |
|
24c05e69d68f
add ODBC library and --list-data-sources mode (DSN)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
47 |
class DataSource { |
24c05e69d68f
add ODBC library and --list-data-sources mode (DSN)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
48 |
public: |
24c05e69d68f
add ODBC library and --list-data-sources mode (DSN)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
49 |
relpipe::reader::string_t name; |
24c05e69d68f
add ODBC library and --list-data-sources mode (DSN)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
50 |
relpipe::reader::string_t description; |
24c05e69d68f
add ODBC library and --list-data-sources mode (DSN)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
51 |
}; |
24c05e69d68f
add ODBC library and --list-data-sources mode (DSN)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
52 |
|
24c05e69d68f
add ODBC library and --list-data-sources mode (DSN)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
53 |
DriverManager(); |
24c05e69d68f
add ODBC library and --list-data-sources mode (DSN)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
54 |
virtual ~DriverManager(); |
24c05e69d68f
add ODBC library and --list-data-sources mode (DSN)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
55 |
std::vector<DataSource> getDataSources(); |
36
91cb012d779a
use ODBC, avoid direct dependency on SQLite
František Kučera <franta-hg@frantovo.cz>
parents:
34
diff
changeset
|
56 |
Connection* getConnectionByDSN(relpipe::reader::string_t dataSourceName, relpipe::reader::string_t userName = L"", relpipe::reader::string_t password = L""); |
47
428c278af4be
rename option --data-source-url to --data-source-string
František Kučera <franta-hg@frantovo.cz>
parents:
37
diff
changeset
|
57 |
Connection* getConnectionByString(relpipe::reader::string_t connectionString); |
34
24c05e69d68f
add ODBC library and --list-data-sources mode (DSN)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
58 |
}; |
24c05e69d68f
add ODBC library and --list-data-sources mode (DSN)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
59 |
|
24c05e69d68f
add ODBC library and --list-data-sources mode (DSN)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
60 |
} |
24c05e69d68f
add ODBC library and --list-data-sources mode (DSN)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
61 |
} |
24c05e69d68f
add ODBC library and --list-data-sources mode (DSN)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
62 |
} |