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 );