OpenTREP Logo  0.07.18
C++ Open Travel Request Parsing Library
Loading...
Searching...
No Matches
DBParams.hpp
Go to the documentation of this file.
1#ifndef __OPENTREP_DBPARAMS_HPP
2#define __OPENTREP_DBPARAMS_HPP
3
4// //////////////////////////////////////////////////////////////////////
5// Import section
6// //////////////////////////////////////////////////////////////////////
7// STL
8#include <sstream>
9#include <string>
10// OpenTrep
13#include <opentrep/DBType.hpp>
14
15namespace OPENTREP {
16
20 typedef std::list<std::string> DBParamsNameList_T;
21
22
26 struct DBParams : public OPENTREP_Abstract {
27 public:
28 // ///////////////////// Getters //////////////////////
32 const DBType& getType() const {
33 return _dbtype;
34 }
35
39 const std::string& getUser() const {
40 return _user;
41 }
42
46 const std::string& getPassword() const {
47 return _passwd;
48 }
49
53 const std::string& getHost() const {
54 return _host;
55 }
56
60 const std::string& getPort() const {
61 return _port;
62 }
63
67 const std::string& getDBName() const {
68 return _dbname;
69 }
70
71
72 public:
73 // /////////////////////// Setters ///////////////////////
77 void setType (const DBType& iType) {
78 _dbtype = iType;
79 }
80
84 void setUser (const std::string& iUser) {
85 _user = iUser;
86 }
87
91 void setPassword (const std::string& iPasswd) {
92 _passwd = iPasswd;
93 }
94
98 void setHost (const std::string& iHost) {
99 _host = iHost;
100 }
101
105 void setPort (const std::string& iPort) {
106 _port = iPort;
107 }
108
112 void setDBName (const std::string& iDBName) {
113 _dbname = iDBName;
114 }
115
116
117 public:
118 // ///////////////////// Busines methods ////////////////////
122 bool checkSQLite () const {
123 if (_dbname.empty() == true) {
124 return false;
125 }
126 return true;
127 }
128
132 bool checkMySQL () const {
133 if (_user.empty() == true || _passwd.empty() == true
134 || _host.empty() == true || _port.empty()
135 || _dbname.empty() == true) {
136 return false;
137 }
138 return true;
139 }
140
141 public:
142 // //////////////////// Display methods //////////////////////
148 void toStream (std::ostream& ioOut) const {
149 ioOut << toString();
150 }
151
156 void fromStream (std::istream&) {
157 }
158
162 std::string toShortString() const {
163 std::ostringstream oStr;
164 oStr << _dbname << "." << _user << "@" << _host << ":" << _port;
165 return oStr.str();
166 }
167
171 std::string toString() const {
172 std::ostringstream oStr;
173 oStr << _dbname << "." << _user << "@" << _host << ":" << _port;
174 return oStr.str();
175 }
176
180 std::string toMySQLConnectionString() const {
181 std::ostringstream oStr;
182 oStr << "db=" << _dbname << " user=" << _user << " password=" << _passwd
183 << " port=" << _port << " host=" << _host;
184 return oStr.str();
185 }
186
190 std::string toSQLiteConnectionString() const {
191 std::ostringstream oStr;
192 oStr << "db=" << _dbname;
193 return oStr.str();
194 }
195
196
197 public:
198 // /////////////// Constructors and Destructors ///////////////////
202 DBParams (const DBType& iDBType,
203 const std::string& iDBUser, const std::string& iDBPasswd,
204 const std::string& iDBHost, const std::string& iDBPort,
205 const std::string& iDBName)
206 : _dbtype (iDBType), _user (iDBUser), _passwd (iDBPasswd),
207 _host (iDBHost), _port (iDBPort), _dbname (iDBName) {
208 }
209 DBParams (const DBType& iDBType, const std::string& iDBName)
210 : _dbtype (iDBType), _dbname (iDBName) {
211 }
212
216 // DBParams();
220 // DBParams (const DBParams&);
221
225 virtual ~DBParams() {}
226
227
228 private:
229 // ///////////////////////// Attributes ////////////////////////
233 DBType _dbtype;
234
238 std::string _user;
239
243 std::string _passwd;
244
248 std::string _host;
249
253 std::string _port;
254
258 std::string _dbname;
259 };
260
261}
262#endif // __OPENTREP_DBPARAMS_HPP
std::list< std::string > DBParamsNameList_T
Definition DBParams.hpp:20
const std::string & getUser() const
Definition DBParams.hpp:39
const std::string & getPort() const
Definition DBParams.hpp:60
virtual ~DBParams()
Definition DBParams.hpp:225
const std::string & getDBName() const
Definition DBParams.hpp:67
void setPassword(const std::string &iPasswd)
Definition DBParams.hpp:91
DBParams(const DBType &iDBType, const std::string &iDBUser, const std::string &iDBPasswd, const std::string &iDBHost, const std::string &iDBPort, const std::string &iDBName)
Definition DBParams.hpp:202
bool checkSQLite() const
Definition DBParams.hpp:122
std::string toShortString() const
Definition DBParams.hpp:162
void toStream(std::ostream &ioOut) const
Definition DBParams.hpp:148
void fromStream(std::istream &)
Definition DBParams.hpp:156
const DBType & getType() const
Definition DBParams.hpp:32
void setUser(const std::string &iUser)
Definition DBParams.hpp:84
const std::string & getPassword() const
Definition DBParams.hpp:46
std::string toString() const
Definition DBParams.hpp:171
std::string toMySQLConnectionString() const
Definition DBParams.hpp:180
bool checkMySQL() const
Definition DBParams.hpp:132
void setType(const DBType &iType)
Definition DBParams.hpp:77
void setDBName(const std::string &iDBName)
Definition DBParams.hpp:112
std::string toSQLiteConnectionString() const
Definition DBParams.hpp:190
void setPort(const std::string &iPort)
Definition DBParams.hpp:105
DBParams(const DBType &iDBType, const std::string &iDBName)
Definition DBParams.hpp:209
void setHost(const std::string &iHost)
Definition DBParams.hpp:98
const std::string & getHost() const
Definition DBParams.hpp:53
Enumeration of database types.
Definition DBType.hpp:17