aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
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-2025 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-2025 *
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_INITILIALIZER_FROM_SQL_H
51# define GUM_LEARNING_DB_INITILIALIZER_FROM_SQL_H
52
53# include <agrum/agrum.h>
54
57
58namespace gum {
59
60 namespace learning {
61
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
197
200
202 virtual DBInitializerFromSQL* clone() const;
203
206
208
209
210 // ##########################################################################
212 // ##########################################################################
213
215
217
220
222
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
275# endif /* GUM_NO_INLINE */
276
277# endif /* GUM_LEARNING_DB_INITILIALIZER_FROM_SQL_H */
278
279#endif /* _ODBC */
The class for initializing DatabaseTable and RawDatabaseTable instances from SQL databases.
The base class for initializing DatabaseTable and RawDatabaseTable instances from CSV files or SQL da...
DBInitializerFromSQL(const std::string &connection_string, const std::string &query, long timeout=0L)
default constructor, especially for sqlite databases
virtual ~DBInitializerFromSQL()
destructor
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
virtual const std::vector< std::string > & currentStringRow_() final
returns the content of the current row using strings
DBInitializerFromSQL(DBInitializerFromSQL &&from)
move constructor
DBInitializerFromSQL(const DBInitializerFromSQL &from)
copy constructor
virtual std::vector< std::string > variableNames_() final
returns the names of the variables
DBInitializerFromSQL & operator=(DBInitializerFromSQL &&from)
move operator
virtual bool nextRow_() final
indicates whether there is a next row to read (and point on it)
virtual DBInitializerFromSQL * clone() const
virtual copy constructor
DBInitializerFromSQL & operator=(const DBInitializerFromSQL &from)
copy operator
IDBInitializer(const InputType type)
default constructor
Class for parsing SQL results using Nanodbc.
include the inlined functions if necessary
Definition CSVParser.h:54
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
STL namespace.
Class for parsing SQL results using Nanodbc.