aGrUM
3.2.0
a C++ library for (probabilistic) graphical models
Toggle main menu visibility
DBInitializerFromSQL.h
Go to the documentation of this file.
1
/****************************************************************************
2
* This file is part of the aGrUM/pyAgrum library. *
3
* *
4
* Copyright (c) 2005-2026 by *
5
* - Pierre-Henri WUILLEMIN(_at_LIP6) *
6
* - Christophe GONZALES(_at_AMU) *
7
* *
8
* The aGrUM/pyAgrum library is free software; you can redistribute it *
9
* and/or modify it under the terms of either : *
10
* *
11
* - the GNU Lesser General Public License as published by *
12
* the Free Software Foundation, either version 3 of the License, *
13
* or (at your option) any later version, *
14
* - the MIT license (MIT), *
15
* - or both in dual license, as here. *
16
* *
17
* (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) *
18
* *
19
* This aGrUM/pyAgrum library is distributed in the hope that it will be *
20
* useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
21
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS *
22
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
23
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
24
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
25
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
26
* OTHER DEALINGS IN THE SOFTWARE. *
27
* *
28
* See LICENCES for more details. *
29
* *
30
* SPDX-FileCopyrightText: Copyright 2005-2026 *
31
* - Pierre-Henri WUILLEMIN(_at_LIP6) *
32
* - Christophe GONZALES(_at_AMU) *
33
* SPDX-License-Identifier: LGPL-3.0-or-later OR MIT *
34
* *
35
* Contact : info_at_agrum_dot_org *
36
* homepage : http://agrum.gitlab.io *
37
* gitlab : https://gitlab.com/agrumery/agrum *
38
* *
39
****************************************************************************/
40
41
48
#ifdef _ODBC
49
50
# ifndef GUM_LEARNING_DB_INITIALIZER_FROM_SQL_H
51
# define GUM_LEARNING_DB_INITIALIZER_FROM_SQL_H
52
53
# include <
agrum/agrum.h
>
54
55
# include <
agrum/base/database/IDBInitializer.h
>
56
# include <
agrum/base/database/nanodbcParser.h
>
57
58
namespace
gum
{
59
60
namespace
learning
{
61
156
class
GUM_SHARED_PUBLIC
DBInitializerFromSQL
:
public
IDBInitializer
{
157
public
:
158
// ##########################################################################
160
// ##########################################################################
162
164
174
DBInitializerFromSQL
(
const
std::string& dataSource,
175
const
std::string& login,
176
const
std::string& password,
177
const
std::string& query,
178
long
timeout = 0L);
179
181
189
DBInitializerFromSQL
(
const
std::string& connection_string,
190
const
std::string& query,
191
long
timeout = 0L);
192
194
196
DBInitializerFromSQL
(
const
DBInitializerFromSQL
& from);
197
199
DBInitializerFromSQL
(
DBInitializerFromSQL
&& from);
200
202
[[nodiscard]]
virtual
DBInitializerFromSQL
*
clone
()
const
;
203
205
virtual
~DBInitializerFromSQL
();
206
208
209
210
// ##########################################################################
212
// ##########################################################################
213
215
217
219
DBInitializerFromSQL
&
operator=
(
const
DBInitializerFromSQL
& from);
220
222
224
DBInitializerFromSQL
&
operator=
(
DBInitializerFromSQL
&& from);
225
227
228
229
protected
:
231
virtual
std::vector< std::string >
variableNames_
() final;
232
234
virtual const
std
::vector<
std
::
string
>&
currentStringRow_
() final;
235
237
virtual
bool
nextRow_
() final;
238
239
240
# ifndef DOXYGEN_SHOULD_SKIP_THIS
241
242
private
:
243
// the string specifying how to connect to the database
244
std::string _connection_string_;
245
246
// the current query
247
std::string _query_;
248
249
// the timeout for executing the queries
250
long
_timeout_;
251
252
// the names of the columns in the query result
253
std::vector< std::string > _var_names_;
254
255
// the nanodbc connection to the database
256
nanodbc::connection _connection_;
257
258
// the parser used for parsing the query results
259
NanodbcParser
_parser_;
260
262
void
_connect_(
const
std::string& connection_string,
long
timeout);
263
264
265
# endif
/* DOXYGEN_SHOULD_SKIP_THIS */
266
};
267
268
}
/* namespace learning */
269
270
}
/* namespace gum */
271
272
// include the inlined functions if necessary
273
# ifndef GUM_NO_INLINE
274
# include <
agrum/base/database/DBInitializerFromSQL_inl.h
>
275
# endif
/* GUM_NO_INLINE */
276
277
# endif
/* GUM_LEARNING_DB_INITIALIZER_FROM_SQL_H */
278
279
#endif
/* _ODBC */
DBInitializerFromSQL_inl.h
The class for initializing DatabaseTable and RawDatabaseTable instances from SQL databases.
IDBInitializer.h
The base class for initializing DatabaseTable and RawDatabaseTable instances from CSV files or SQL da...
agrum.h
gum::learning::DBInitializerFromSQL::DBInitializerFromSQL
DBInitializerFromSQL(const std::string &connection_string, const std::string &query, long timeout=0L)
default constructor, especially for sqlite databases
gum::learning::DBInitializerFromSQL::~DBInitializerFromSQL
virtual ~DBInitializerFromSQL()
destructor
gum::learning::DBInitializerFromSQL::DBInitializerFromSQL
DBInitializerFromSQL(const std::string &dataSource, const std::string &login, const std::string &password, const std::string &query, long timeout=0L)
default constructor, especially for postgresql databases
gum::learning::DBInitializerFromSQL::currentStringRow_
virtual const std::vector< std::string > & currentStringRow_() final
returns the content of the current row using strings
gum::learning::DBInitializerFromSQL::DBInitializerFromSQL
DBInitializerFromSQL(DBInitializerFromSQL &&from)
move constructor
gum::learning::DBInitializerFromSQL::DBInitializerFromSQL
DBInitializerFromSQL(const DBInitializerFromSQL &from)
copy constructor
gum::learning::DBInitializerFromSQL::variableNames_
virtual std::vector< std::string > variableNames_() final
returns the names of the variables
gum::learning::DBInitializerFromSQL::operator=
DBInitializerFromSQL & operator=(DBInitializerFromSQL &&from)
move operator
gum::learning::DBInitializerFromSQL::nextRow_
virtual bool nextRow_() final
indicates whether there is a next row to read (and point on it)
gum::learning::DBInitializerFromSQL::clone
virtual DBInitializerFromSQL * clone() const
virtual copy constructor
gum::learning::DBInitializerFromSQL::operator=
DBInitializerFromSQL & operator=(const DBInitializerFromSQL &from)
copy operator
gum::learning::IDBInitializer::IDBInitializer
IDBInitializer(const InputType type)
default constructor
gum::learning::NanodbcParser
Class for parsing SQL results using Nanodbc.
Definition
nanodbcParser.h:53
gum::learning
include the inlined functions if necessary
Definition
CSVParser.h:55
gum
gum is the global namespace for all aGrUM entities
Definition
agrum.h:46
std
STL namespace.
nanodbcParser.h
Class for parsing SQL results using Nanodbc.
aGrUM
3.2.0
© PHW&CG&others - 2022
DoXyGeN 1.18.0