aGrUM  0.16.0
nanodbcParser.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  ***************************************************************************/
27 #ifdef _ODBC
28 
29 #ifndef GUM_NANODBC_PARSER_H
30 #define GUM_NANODBC_PARSER_H
31 
32 #include <string>
33 #include <cstdlib>
34 #include <vector>
35 #include <stdexcept>
36 #include <sql.h>
37 
38 #include <agrum/agrum.h>
40 
41 namespace gum {
42 
43  namespace learning {
44 
53  template <template<typename> class ALLOC = std::allocator>
54  class NanodbcParser {
55  public:
56 
58  using allocator_type = ALLOC<std::string>;
59 
60 
61  // ##########################################################################
63  // ##########################################################################
65 
67  NanodbcParser( const ALLOC<std::string>& alloc = ALLOC<std::string>() );
68 
70 
74  NanodbcParser( nanodbc::connection& connection,
75  const std::string& query,
76  const ALLOC<std::string>& alloc = ALLOC<std::string> () );
77 
79  virtual ~NanodbcParser();
80 
82 
83 
84  // ########################################################################
86  // ########################################################################
88 
90 
91  bool next();
92 
94 
95  const std::vector<std::string,ALLOC<std::string>>& current() const;
96 
98  std::size_t nbLine() const;
99 
101  std::size_t nbColumns () const;
102 
104  std::string columnName ( const std::size_t i ) const;
105 
107  void useNewQuery ( nanodbc::connection& connexion,
108  const std::string& query );
109 
111 
112 
113 #ifndef DOXYGEN_SHOULD_SKIP_THIS
114 
115  private:
116 
117  // the result of the last SQL query performed
118  nanodbc::result __result;
119 
120  // the line number within the current query
121  std::size_t __nb_line { std::size_t(0) };
122 
123  // a vector that will contain the content of the current line of result
124  std::vector<std::string,ALLOC<std::string>> __data;
125 
126 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
127 
128  };
129 
130  } // namespace learning
131 
132 } // namespace gum
133 
135 
136 #endif // GUM_NANODBC_PARSER_H
137 
138 #endif // _ODBC
std::string columnName(const std::size_t i) const
returns the name of the ith column
Class for parsing SQL results using Nanodbc.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
ALLOC< std::string > allocator_type
type for the allocators passed in arguments of methods
Definition: nanodbcParser.h:58
std::size_t nbLine() const
returns the current line number within the query
virtual ~NanodbcParser()
destructor
void useNewQuery(nanodbc::connection &connexion, const std::string &query)
start a new query
bool next()
Gets the next line of the SQL stream and parses it.
Class for parsing SQL results using Nanodbc.
Definition: nanodbcParser.h:54
const std::vector< std::string, ALLOC< std::string > > & current() const
returns the current parsed line.
std::size_t nbColumns() const
returns the number of columns in the query result
NanodbcParser(const ALLOC< std::string > &alloc=ALLOC< std::string >())
Default constructor: create a parser without being connected.