33 # ifndef DOXYGEN_SHOULD_SKIP_THIS 44 template <
template <
typename >
class ALLOC >
45 void DBInitializerFromSQL< ALLOC >::__connect(
46 const std::string& connection_string,
long timeout) {
50 bool agrum_connection = (connection_string.size() > 4)
51 && (connection_string.compare(0, 4,
"gum ") == 0);
54 if (!agrum_connection) {
55 __connection.connect(connection_string, timeout);
57 std::size_t deb_index, end_index;
58 const std::string delimiter =
"|";
60 deb_index = connection_string.find(delimiter, 0);
61 if (deb_index == std::string::npos)
63 "could not determine the datasource from string " 64 << connection_string);
65 deb_index += std::size_t(1);
66 end_index = connection_string.find(delimiter, deb_index);
67 if (end_index == std::string::npos)
69 "could not determine the datasource from string " 70 << connection_string);
71 std::string dataSource =
72 connection_string.substr(deb_index, end_index - deb_index);
74 deb_index = connection_string.find(delimiter, end_index + std::size_t(1));
75 if (deb_index == std::string::npos)
77 "could not determine the database login from string " 78 << connection_string);
79 deb_index += std::size_t(1);
80 end_index = connection_string.find(delimiter, deb_index);
81 if (end_index == std::string::npos)
83 "could not determine the database login from string " 84 << connection_string);
86 connection_string.substr(deb_index, end_index - deb_index);
88 deb_index = connection_string.find(delimiter, end_index + std::size_t(1));
89 if (deb_index == std::string::npos)
91 "could not determine the database password from string " 92 << connection_string);
93 deb_index += std::size_t(1);
94 end_index = connection_string.find(delimiter, deb_index);
95 if (end_index == std::string::npos)
97 "could not determine the database password from string " 98 << connection_string);
99 std::string password =
100 connection_string.substr(deb_index, end_index - deb_index);
102 __connection.connect(dataSource, login, password, timeout);
108 template <
template <
typename >
class ALLOC >
110 const std::string& connection_string,
111 const std::string& query,
114 IDBInitializer< ALLOC >(IDBInitializer< ALLOC >::InputType::STRING, alloc),
115 __connection_string(connection_string), __query(query), __timeout(timeout),
116 __var_names(alloc), __parser(alloc) {
119 const std::string current_locale = std::setlocale(LC_NUMERIC, NULL);
122 __connect(connection_string, timeout);
125 std::setlocale(LC_NUMERIC, current_locale.c_str());
128 __parser.useNewQuery(__connection, __query);
131 const std::size_t nb_cols = std::size_t(__parser.nbColumns());
132 for (std::size_t i = 0; i < nb_cols; ++i) {
133 __var_names.push_back(__parser.columnName(i));
141 template <
template <
typename >
class ALLOC >
143 const std::string& dataSource,
144 const std::string& login,
145 const std::string& password,
146 const std::string& query,
150 +
"|; login=|" + login +
"|; password=|" 158 template <
template <
typename >
class ALLOC >
160 const DBInitializerFromSQL< ALLOC >& from,
163 from.__connection_string, from.__query, from.__timeout, alloc) {}
167 template <
template <
typename >
class ALLOC >
169 const DBInitializerFromSQL< ALLOC >& from) :
174 template <
template <
typename >
class ALLOC >
176 DBInitializerFromSQL< ALLOC >&& from,
179 from.__connection_string, from.__query, from.__timeout, alloc) {}
182 template <
template <
typename >
class ALLOC >
184 DBInitializerFromSQL< ALLOC >&& from) :
189 template <
template <
typename >
class ALLOC >
192 ALLOC< DBInitializerFromSQL< ALLOC > > allocator(alloc);
193 DBInitializerFromSQL< ALLOC >* new_initializer = allocator.allocate(1);
195 allocator.construct(new_initializer, *
this, alloc);
197 allocator.deallocate(new_initializer, 1);
201 return new_initializer;
206 template <
template <
typename >
class ALLOC >
213 template <
template <
typename >
class ALLOC >
220 template <
template <
typename >
class ALLOC >
222 operator=(
const DBInitializerFromSQL< ALLOC >& from) {
226 const bool connexion_changed =
227 (__connection_string != from.__connection_string);
230 __connection_string = from.__connection_string;
231 __query = from.__query;
232 __timeout = from.__timeout;
235 if (connexion_changed) {
236 if (__connection.connected()) __connection.disconnect();
237 __connect(__connection_string, __timeout);
241 __parser.useNewQuery(__connection, __query);
245 const std::size_t nb_cols = std::size_t(__parser.nbColumns());
246 for (std::size_t i = 0; i < nb_cols; ++i) {
247 __var_names.push_back(__parser.columnName(i));
256 template <
template <
typename >
class ALLOC >
258 operator=(DBInitializerFromSQL< ALLOC >&& from) {
264 template <
template <
typename >
class ALLOC >
265 INLINE std::vector< std::string, ALLOC< std::string > >
272 template <
template <
typename >
class ALLOC >
273 INLINE
const std::vector< std::string, ALLOC< std::string > >&
275 return __parser.current();
280 template <
template <
typename >
class ALLOC >
282 return __parser.next();
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
allocator_type getAllocator() const
returns the allocator used
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
IDBInitializer< ALLOC > & operator=(const IDBInitializer< ALLOC > &from)
copy operator
virtual std::vector< std::string, ALLOC< std::string > > _variableNames() final
returns the names of the variables
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
virtual ~DBInitializerFromSQL()
destructor
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
#define GUM_ERROR(type, msg)