29 #ifndef DOXYGEN_SHOULD_SKIP_THIS 39 template <
template<
typename>
class ALLOC>
47 template <
template<
typename>
class ALLOC>
49 const std::string& query,
50 const ALLOC<std::string>& alloc )
53 if ( connexion.connected () ) {
54 __result = nanodbc::execute( connexion, query );
55 __data.resize ( std::size_t ( __result.columns() ) );
62 template <
template<
typename>
class ALLOC>
69 template <
template<
typename>
class ALLOC>
87 if ( __result.next() ) {
88 const std::size_t nb_cols = std::size_t ( __result.columns() );
90 for ( std::size_t i = 0; i < nb_cols; ++i ) {
91 const short pos ( i );
93 const int type = __result.column_datatype ( pos );
99 if ( ( type >= SQL_NUMERIC ) && ( type <= SQL_DOUBLE ) ) {
100 sprintf ( str,
"%g", __result.get<
float>( pos ) );
104 __data[i] = __result.get<std::string>( pos );
106 }
catch ( nanodbc::null_access_error& e ) {
113 }
catch ( std::runtime_error& e ) {
114 GUM_ERROR( DatabaseError, std::string( e.what() ) );
122 template <
template<
typename>
class ALLOC>
124 return __nb_line >= 1 ? __nb_line - 1 : std::size_t(0);
129 template <
template<
typename>
class ALLOC>
131 const std::vector<std::string,ALLOC<std::string>>&
133 if ( ! __data.empty () ) {
137 GUM_ERROR( NullElement,
"No parsed data" );
142 template <
template<
typename>
class ALLOC>
144 const std::string& query ) {
145 __result = nanodbc::execute( connexion, query );
146 __data.resize ( std::size_t ( __result.columns() ) );
147 __nb_line = std::size_t(0);
152 template <
template<
typename>
class ALLOC>
154 return std::size_t ( __result.columns () );
159 template <
template<
typename>
class ALLOC>
162 return __result.column_name( i );
std::string columnName(const std::size_t i) const
returns the name of the ith column
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
std::size_t nbLine() const
returns the current line number within the query
virtual ~NanodbcParser()
destructor
Class for parsing SQL results using Nanodbc.
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.
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.
#define GUM_ERROR(type, msg)