29 #ifndef DOXYGEN_SHOULD_SKIP_THIS 31 #include <agrum/tools/database/nanodbcParser.h> 39 template <
template<
typename>
class ALLOC>
40 NanodbcParser<ALLOC>::NanodbcParser(
const ALLOC<std::string>& alloc )
42 GUM_CONSTRUCTOR( NanodbcParser );
47 template <
template<
typename>
class ALLOC>
48 NanodbcParser<ALLOC>::NanodbcParser( nanodbc::connection& connexion,
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() ) );
57 GUM_CONSTRUCTOR( NanodbcParser );
62 template <
template<
typename>
class ALLOC>
63 NanodbcParser<ALLOC>::~NanodbcParser() {
64 GUM_DESTRUCTOR( NanodbcParser );
69 template <
template<
typename>
class ALLOC>
70 bool NanodbcParser<ALLOC>::next() {
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>
123 INLINE std::size_t NanodbcParser<ALLOC>::nbLine()
const {
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>>&
132 NanodbcParser<ALLOC>::current()
const {
133 if ( ! data__.empty () ) {
137 GUM_ERROR( NullElement,
"No parsed data" );
142 template <
template<
typename>
class ALLOC>
143 void NanodbcParser<ALLOC>::useNewQuery ( nanodbc::connection& connexion,
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>
153 INLINE std::size_t NanodbcParser<ALLOC>::nbColumns ()
const {
154 return std::size_t ( result__.columns () );
159 template <
template<
typename>
class ALLOC>
161 NanodbcParser<ALLOC>::columnName (
const std::size_t i )
const {
162 return result__.column_name( i );