- Timestamp:
- 06/02/12 21:24:58 (12 years ago)
- Location:
- trunk/FACT++/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/Configuration.cc
r14038 r14045 332 332 #include <iomanip> 333 333 334 #include <boost/regex.hpp>335 334 #include <boost/filesystem.hpp> 336 335 337 336 #ifdef HAVE_SQL 338 #include <mysql++/mysql++.h>337 #include "Database.h" 339 338 #endif 340 339 … … 391 390 Configuration::parse_database(const string &prgname, const string &database, const po::options_description& desc, bool allow_unregistered) 392 391 { 393 //static const boost::regex expr("(([[:word:].-]+)(:(.+))?@)?([[:word:].-]+)(:([[:digit:]]+))?(/([[:word:].-]+))?"); 394 static const boost::regex expr("(([[:word:].-]+)(:(.+))?@)?([[:word:].-]+)(:([[:digit:]]+))?(/([[:word:].-]+))"); 395 // 2: user 396 // 4: pass 397 // 5: server 398 // 7: port 399 // 9: db 400 401 boost::smatch what; 402 if (!boost::regex_match(database, what, expr, boost::match_extra)) 403 throw runtime_error("Couldn't parse '"+database+"'."); 404 405 if (what.size()!=10) 406 throw runtime_error("Error parsing '"+database+"'."); 407 408 const string user = what[2]; 409 const string passwd = what[4]; 410 const string server = what[5]; 411 const string db = what[9]; 412 const int port = atoi(string(what[7]).c_str()); 413 414 cout << "Connecting to '"; 415 if (!user.empty()) 416 cout << user << "@"; 417 cout << server; 418 if (port) 419 cout << ":" << port; 420 if (!db.empty()) 421 cout << "/" << db; 422 cout << "' for " << prgname << endl; 423 424 mysqlpp::Connection conn(db.c_str(), server.c_str(), user.c_str(), passwd.c_str(), port); 425 /* throws exceptions 426 if (!conn.connected()) 427 { 428 cout << "MySQL connection error: " << conn.error() << endl; 429 throw; 430 }*/ 392 Database db(database); 393 394 cout << "Connected to '" << db.database() << "' for " << prgname << endl; 431 395 432 396 const mysqlpp::StoreQueryResult res = 433 conn.query("SELECT CONCAT(fKey1,fKey2), fValue " 434 "FROM ProgramOption " 435 "WHERE fCounter=(SELECT MAX(fCounter) FROM History) " 436 "AND NOT ISNULL(fValue) " 437 "AND (fProgram='"+prgname+"' OR fProgram='*')").store(); 438 /* throws exceptions 439 if (!res) 440 { 441 cout << "MySQL query failed: " << query.error() << endl; 442 throw; 443 }*/ 397 db.query("SELECT CONCAT(fKey1,fKey2), fValue " 398 "FROM ProgramOption " 399 "WHERE fCounter=(SELECT MAX(fCounter) FROM History) " 400 "AND NOT ISNULL(fValue) " 401 "AND (fProgram='"+prgname+"' OR fProgram='*')").store(); 444 402 445 403 set<string> allowed_options; -
trunk/FACT++/src/drivectrl.cc
r14039 r14045 8 8 9 9 #ifdef HAVE_SQL 10 #include <mysql++/mysql++.h>10 #include "Database.h" 11 11 #endif 12 12 … … 1226 1226 { 1227 1227 #ifdef HAVE_SQL 1228 //static const boost::regex expr("(([[:word:].-]+)(:(.+))?@)?([[:word:].-]+)(:([[:digit:]]+))?(/([[:word:].-]+))?"); 1229 static const boost::regex expr("(([[:word:].-]+)(:(.+))?@)?([[:word:].-]+)(:([[:digit:]]+))?(/([[:word:].-]+))"); 1230 // 2: user 1231 // 4: pass 1232 // 5: server 1233 // 7: port 1234 // 9: db 1235 1236 boost::smatch what; 1237 if (!boost::regex_match(fDatabase, what, expr, boost::match_extra)) 1238 throw runtime_error("Couldn't parse '"+fDatabase+"'."); 1239 1240 if (what.size()!=10) 1241 throw runtime_error("Error parsing '"+fDatabase+"'."); 1242 1243 const string user = what[2]; 1244 const string passwd = what[4]; 1245 const string server = what[5]; 1246 const string db = what[9]; 1247 const int port = atoi(string(what[7]).c_str()); 1248 1249 ostringstream out; 1250 out << "Connecting to '"; 1251 if (!user.empty()) 1252 out << user << "@"; 1253 out << server; 1254 if (port) 1255 out << ":" << port; 1256 if (!db.empty()) 1257 out << "/" << db; 1258 1259 T::Message(out); 1260 1261 mysqlpp::Connection conn(db.c_str(), server.c_str(), user.c_str(), passwd.c_str(), port); 1262 /* throws exceptions 1263 if (!conn.connected()) 1264 { 1265 cout << "MySQL connection error: " << conn.error() << endl; 1266 throw; 1267 }*/ 1228 Database db(fDatabase); 1229 1230 T::Message("Connected to '"+db.database()+"'"); 1268 1231 1269 1232 const mysqlpp::StoreQueryResult res = 1270 conn.query("SELECT fSourceName, fRightAscension, fDeclination FROM source").store(); 1271 /* throws exceptions 1272 if (!res) 1273 { 1274 cout << "MySQL query failed: " << query.error() << endl; 1275 throw; 1276 }*/ 1233 db.query("SELECT fSourceName, fRightAscension, fDeclination FROM source").store(); 1277 1234 1278 1235 fSources.clear(); -
trunk/FACT++/src/smartfact.cc
r14043 r14045 7 7 8 8 #ifdef HAVE_SQL 9 #include <mysql++/mysql++.h>9 #include "Database.h" 10 10 #endif 11 11 … … 1739 1739 try 1740 1740 { 1741 static const boost::regex expr("(([[:word:].-]+)(:(.+))?@)?([[:word:].-]+)(:([[:digit:]]+))?(/([[:word:].-]+))");1742 1743 boost::smatch what;1744 if (!boost::regex_match(fDatabase, what, expr, boost::match_extra))1745 throw runtime_error("Couldn't parse '"+fDatabase+"'.");1746 1747 if (what.size()!=10)1748 throw runtime_error("Error parsing '"+fDatabase+"'.");1749 1750 const string user = what[2];1751 const string passwd = what[4];1752 const string server = what[5];1753 const string db = what[9];1754 const int port = atoi(string(what[7]).c_str());1755 1756 mysqlpp::Connection conn(db.c_str(), server.c_str(), user.c_str(), passwd.c_str(), port);1757 1758 1741 const mysqlpp::StoreQueryResult res = 1759 conn.query("SELECT fSourceName, fRightAscension, fDeclination FROM source").store();1742 Database(fDatabase).query("SELECT fSourceName, fRightAscension, fDeclination FROM source").store(); 1760 1743 1761 1744 out << HTML::kWhite << '\t';
Note:
See TracChangeset
for help on using the changeset viewer.