aGrUM  0.16.0
DBInitializerFromSQL.h
Go to the documentation of this file.
1 
29 #ifdef _ODBC
30 
31 # ifndef GUM_LEARNING_DB_INITILIALIZER_FROM_SQL_H
32 # define GUM_LEARNING_DB_INITILIALIZER_FROM_SQL_H
33 
34 # include <agrum/agrum.h>
37 
38 namespace gum {
39 
40  namespace learning {
41 
136  template < template < typename > class ALLOC = std::allocator >
137  class DBInitializerFromSQL : public IDBInitializer< ALLOC > {
138  public:
140  using allocator_type = ALLOC< std::string >;
141 
142  // ##########################################################################
144  // ##########################################################################
146 
148 
159  DBInitializerFromSQL(const std::string& dataSource,
160  const std::string& login,
161  const std::string& password,
162  const std::string& query,
163  long timeout = 0L,
164  const allocator_type& alloc = allocator_type());
165 
167 
176  DBInitializerFromSQL(const std::string& connection_string,
177  const std::string& query,
178  long timeout = 0L,
179  const allocator_type& alloc = allocator_type());
180 
182 
185 
187 
190  const allocator_type& alloc);
191 
194 
197  const allocator_type& alloc);
198 
200  virtual DBInitializerFromSQL< ALLOC >* clone() const;
201 
204  clone(const allocator_type& alloc) const;
205 
207  virtual ~DBInitializerFromSQL();
208 
210 
211 
212  // ##########################################################################
214  // ##########################################################################
215 
217 
219 
223 
225 
229 
231 
232 
233  protected:
235  virtual std::vector< std::string, ALLOC< std::string > >
236  _variableNames() final;
237 
239  virtual const std::vector< std::string, ALLOC< std::string > >&
240  _currentStringRow() final;
241 
243  virtual bool _nextRow() final;
244 
245 
246 # ifndef DOXYGEN_SHOULD_SKIP_THIS
247 
248  private:
249  // the string specifying how to connect to the database
250  std::string __connection_string;
251 
252  // the current query
253  std::string __query;
254 
255  // the timeout for executing the queries
256  long __timeout;
257 
258  // the names of the columns in the query result
259  std::vector< std::string, ALLOC< std::string > > __var_names;
260 
261  // the nanodbc connection to the database
262  nanodbc::connection __connection;
263 
264  // the parser used for parsing the query results
265  NanodbcParser< ALLOC > __parser;
266 
268  void __connect(const std::string& connection_string, long timeout);
269 
270 
271 # endif /* DOXYGEN_SHOULD_SKIP_THIS */
272  };
273 
274  } /* namespace learning */
275 
276 } /* namespace gum */
277 
278 // always include the template implementation
280 
281 # endif /* GUM_LEARNING_DB_INITILIALIZER_FROM_SQL_H */
282 
283 #endif /* _ODBC */
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
The class for initializing DatabaseTable and RawDatabaseTable instances from SQL databases.
virtual DBInitializerFromSQL< ALLOC > * clone() const
virtual copy constructor
virtual bool _nextRow() final
indicates whether there is a next row to read (and point on it)
DBInitializerFromSQL(const std::string &dataSource, const std::string &login, const std::string &password, const std::string &query, long timeout=0L, const allocator_type &alloc=allocator_type())
default constructor, especially for postgresql databases
ALLOC< std::string > allocator_type
type for the allocators passed in arguments of methods
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
STL namespace.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
virtual std::vector< std::string, ALLOC< std::string > > _variableNames() final
returns the names of the variables
virtual ~DBInitializerFromSQL()
destructor
Class for parsing SQL results using Nanodbc.
DBInitializerFromSQL< ALLOC > & operator=(const DBInitializerFromSQL< ALLOC > &from)
copy operator
virtual const std::vector< std::string, ALLOC< std::string > > & _currentStringRow() final
returns the content of the current row using strings
Class for parsing SQL results using Nanodbc.
Definition: nanodbcParser.h:54
The base class for initializing DatabaseTable and RawDatabaseTable instances from CSV files or SQL da...