9#include <boost/tokenizer.hpp>
25 typedef boost::tokenizer<boost::char_separator<char> > Tokeniser_T;
30 const boost::char_separator<char>
31 lSepatorList(
" .,;:|+-*/_=!@#$%`~^&(){}[]?'<>\"");
34 Tokeniser_T lTokens (iPhrase, lSepatorList);
35 for (Tokeniser_T::const_iterator tok_iter = lTokens.begin();
36 tok_iter != lTokens.end(); ++tok_iter) {
37 const std::string& lTerm = *tok_iter;
38 ioWordList.push_back (lTerm);
45 const bool iFromBeginningFlag) {
46 std::ostringstream oStr;
50 WordList_T::const_iterator itWord = iWordList.begin();
51 for ( ; itWord != iWordList.end(); ++itWord, ++idx) {
53 if (iFromBeginningFlag ==
true) {
58 if (iSplitIdx != 0 && idx >= iSplitIdx) {
67 const std::string& lWord = *itWord;
75 if (iSplitIdx == 0 || idx >= iSplitIdx) {
82 if (iFromBeginningFlag ==
true) {
87 assert (iFromBeginningFlag ==
false);
90 for ( ; itWord != iWordList.end(); ++itWord, ++idx) {
94 if (idx > iSplitIdx) {
98 const std::string& lWord = *itWord;
116 std::stringstream lConnStream (iSQLDBConnStr);
119 while (std::getline (lConnStream, kvStr,
' ')) {
124 const size_t eqPos = kvStr.find (
'=');
125 if (eqPos == std::string::npos) {
129 const std::string lKey = kvStr.substr (0, eqPos);
130 const std::string lVal = kvStr.substr (eqPos + 1);
131 oStrMap[lKey] = lVal;
138 const StringMap_T::const_iterator itDBName = oStrMap.find (
"db");
139 if (itDBName == oStrMap.end()) {
140 std::ostringstream errStr;
141 errStr <<
"Error when parsing the SQL database connection string ('"
142 << iSQLDBConnStr <<
"'), the 'db' value cannot be found";
148 const StringMap_T::const_iterator itDBUser = oStrMap.find (
"user");
149 if (itDBUser == oStrMap.end()) {
150 std::ostringstream errStr;
151 errStr <<
"Error when parsing the SQL database connection string ('"
152 << iSQLDBConnStr <<
"'), the 'user' value cannot be found";
158 const StringMap_T::const_iterator itDBPasswd = oStrMap.find (
"password");
159 if (itDBPasswd == oStrMap.end()) {
160 std::ostringstream errStr;
161 errStr <<
"Error when parsing the SQL database connection string ('"
162 << iSQLDBConnStr <<
"'), the 'password' value cannot be found";
171 SQLDBConnectionString_T
174 std::ostringstream oStr;
177 const StringMap_T::const_iterator itDBName = iStringMap.find (
"db");
178 assert (itDBName != iStringMap.end());
179 const std::string& lDBName = itDBName->second;
182 const StringMap_T::const_iterator itDBUser = iStringMap.find (
"user");
183 assert (itDBUser != iStringMap.end());
184 const std::string& lDBUser = itDBUser->second;
187 const StringMap_T::const_iterator itDBPasswd = iStringMap.find (
"password");
188 assert (itDBPasswd != iStringMap.end());
189 const std::string& lDBPasswd = itDBPasswd->second;
192 oStr <<
"db=" << lDBName;
193 if (lDBName !=
"mysql") {
194 oStr << iDeploymentNumber;
198 oStr <<
" user=" << lDBUser;
201 oStr <<
" password=" << lDBPasswd;
207 const StringMap_T::const_iterator itHost = iStringMap.find (
"host");
208 if (itHost != iStringMap.end()) {
209 oStr <<
" host=" << itHost->second;
212 const StringMap_T::const_iterator itPort = iStringMap.find (
"port");
213 if (itPort != iStringMap.end()) {
214 oStr <<
" port=" << itPort->second;
224 std::ostringstream oStr;
226 for (StringMap_T::const_iterator itDBKV = iStringMap.begin();
227 itDBKV != iStringMap.end(); ++itDBKV) {
228 const std::string& lDBKey = itDBKV->first;
229 const std::string& lDBValue = itDBKV->second;
230 oStr << lDBKey <<
"=";
232 if (lDBKey ==
"db" && lDBValue !=
"mysql"
234 oStr << iDeploymentNumber;
249 std::stringstream lConnStream (iSQLDBConnStr);
252 while (std::getline (lConnStream, kvStr,
' ')) {
257 const size_t eqPos = kvStr.find (
'=');
258 if (eqPos == std::string::npos) {
262 const std::string lKey = kvStr.substr (0, eqPos);
263 const std::string lVal = kvStr.substr (eqPos + 1);
264 oStrMap[lKey] = lVal;
268 if (oStrMap.find (
"dbname") == oStrMap.end()) {
269 std::ostringstream errStr;
270 errStr <<
"Error when parsing the PG connection string ('"
271 << iSQLDBConnStr <<
"'), the 'dbname' value cannot be found";
276 if (oStrMap.find (
"user") == oStrMap.end()) {
277 std::ostringstream errStr;
278 errStr <<
"Error when parsing the PG connection string ('"
279 << iSQLDBConnStr <<
"'), the 'user' value cannot be found";
284 if (oStrMap.find (
"password") == oStrMap.end()) {
285 std::ostringstream errStr;
286 errStr <<
"Error when parsing the PG connection string ('"
287 << iSQLDBConnStr <<
"'), the 'password' value cannot be found";
296 SQLDBConnectionString_T
299 std::ostringstream oStr;
301 const StringMap_T::const_iterator itDBName = iStringMap.find (
"dbname");
302 assert (itDBName != iStringMap.end());
303 oStr <<
"dbname=" << itDBName->second << iDeploymentNumber;
305 const StringMap_T::const_iterator itDBUser = iStringMap.find (
"user");
306 assert (itDBUser != iStringMap.end());
307 oStr <<
" user=" << itDBUser->second;
309 const StringMap_T::const_iterator itDBPasswd = iStringMap.find (
"password");
310 assert (itDBPasswd != iStringMap.end());
311 oStr <<
" password=" << itDBPasswd->second;
314 const StringMap_T::const_iterator itHost = iStringMap.find (
"host");
315 if (itHost != iStringMap.end()) {
316 oStr <<
" host=" << itHost->second;
319 const StringMap_T::const_iterator itPort = iStringMap.find (
"port");
320 if (itPort != iStringMap.end()) {
321 oStr <<
" port=" << itPort->second;
331 std::ostringstream oStr;
333 for (StringMap_T::const_iterator itDBKV = iStringMap.begin();
334 itDBKV != iStringMap.end(); ++itDBKV) {
335 const std::string& lDBKey = itDBKV->first;
336 const std::string& lDBValue = itDBKV->second;
337 oStr << lDBKey <<
"=";
339 if (lDBKey ==
"dbname"
341 oStr << iDeploymentNumber;
352 const std::string& iSQLDBConnStr,
354 std::ostringstream oStr;
361 oStr << iSQLDBConnStr << iDeploymentNumber;
370 const std::string& lNewSQLDBConnStr =
372 oStr << lNewSQLDBConnStr;
381 const std::string& lNewSQLDBConnStr =
383 oStr << lNewSQLDBConnStr;
#define OPENTREP_LOG_ERROR(iToBeLogged)
std::list< Word_T > WordList_T
void tokeniseStringIntoWordList(const std::string &iPhrase, WordList_T &ioWordList)
SQLDBConnectionString_T buildMySQLConnectionString(const StringMap_T &iStringMap, const DeploymentNumber_T &iDeploymentNumber)
std::string createStringFromWordList(const WordList_T &iWordList, const NbOfWords_T iSplitIdx, const bool iFromBeginningFlag)
std::string displayMySQLConnectionString(const StringMap_T &iStringMap, const DeploymentNumber_T &iDeploymentNumber)
const unsigned short DEFAULT_OPENTREP_DEPLOYMENT_NUMBER_SIZE
SQLDBConnectionString_T buildPGConnectionString(const StringMap_T &iStringMap, const DeploymentNumber_T &iDeploymentNumber)
std::string displayPGConnectionString(const StringMap_T &iStringMap, const DeploymentNumber_T &iDeploymentNumber)
std::string parseAndDisplayConnectionString(const DBType &iDBType, const std::string &iSQLDBConnStr, const DeploymentNumber_T &iDeploymentNumber)
StringMap_T parseMySQLConnectionString(const SQLDBConnectionString_T &iSQLDBConnStr)
unsigned short DeploymentNumber_T
StringMap_T parsePGConnectionString(const SQLDBConnectionString_T &iSQLDBConnStr)
std::map< const std::string, std::string > StringMap_T
unsigned short NbOfWords_T
Enumeration of database types.