aGrUM  0.14.2
DBInitializerFromSQL.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Christophe GONZALES and Pierre-Henri WUILLEMIN *
3  * {prenom.nom}_at_lip6.fr *
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 2 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, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
26 #ifdef _ODBC
27 
28 # ifndef GUM_LEARNING_DB_INITILIALIZER_FROM_SQL_H
29 # define GUM_LEARNING_DB_INITILIALIZER_FROM_SQL_H
30 
31 # include <agrum/agrum.h>
34 
35 namespace gum {
36 
37  namespace learning {
38 
133  template < template < typename > class ALLOC = std::allocator >
134  class DBInitializerFromSQL : public IDBInitializer< ALLOC > {
135  public:
137  using allocator_type = ALLOC< std::string >;
138 
139  // ##########################################################################
141  // ##########################################################################
143 
145 
156  DBInitializerFromSQL(const std::string& dataSource,
157  const std::string& login,
158  const std::string& password,
159  const std::string& query,
160  long timeout = 0L,
161  const allocator_type& alloc = allocator_type());
162 
164 
173  DBInitializerFromSQL(const std::string& connection_string,
174  const std::string& query,
175  long timeout = 0L,
176  const allocator_type& alloc = allocator_type());
177 
179 
182 
184 
187  const allocator_type& alloc);
188 
191 
194  const allocator_type& alloc);
195 
197  virtual DBInitializerFromSQL< ALLOC >* clone() const;
198 
201  clone(const allocator_type& alloc) const;
202 
204  virtual ~DBInitializerFromSQL();
205 
207 
208 
209  // ##########################################################################
211  // ##########################################################################
212 
214 
216 
220 
222 
226 
228 
229 
230  protected:
232  virtual std::vector< std::string, ALLOC< std::string > >
233  _variableNames() final;
234 
236  virtual const std::vector< std::string, ALLOC< std::string > >&
237  _currentStringRow() final;
238 
240  virtual bool _nextRow() final;
241 
242 
243 # ifndef DOXYGEN_SHOULD_SKIP_THIS
244 
245  private:
246  // the string specifying how to connect to the database
247  std::string __connection_string;
248 
249  // the current query
250  std::string __query;
251 
252  // the timeout for executing the queries
253  long __timeout;
254 
255  // the names of the columns in the query result
256  std::vector< std::string, ALLOC< std::string > > __var_names;
257 
258  // the nanodbc connection to the database
259  nanodbc::connection __connection;
260 
261  // the parser used for parsing the query results
262  NanodbcParser< ALLOC > __parser;
263 
265  void __connect(const std::string& connection_string, long timeout);
266 
267 
268 # endif /* DOXYGEN_SHOULD_SKIP_THIS */
269  };
270 
271  } /* namespace learning */
272 
273 } /* namespace gum */
274 
275 // always include the template implementation
277 
278 # endif /* GUM_LEARNING_DB_INITILIALIZER_FROM_SQL_H */
279 
280 #endif /* _ODBC */
The base class for initializing DatabaseTable and RawDatabaseTable instances from CSV files or SQL da...
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
The class for initializing DatabaseTable and RawDatabaseTable instances from SQL databases.
STL namespace.
gum is the global namespace for all aGrUM entities
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...