mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-19 21:29:06 +00:00
fixing user_handler reconnection to db
This commit is contained in:
parent
3f6b680e2f
commit
29bf4d31b1
@ -224,20 +224,17 @@ void fuh::set_lastlogin(const std::string& user, const time_t& lastlogin) {
|
||||
}
|
||||
|
||||
mysqlpp::Result fuh::db_query(const std::string& sql) {
|
||||
|
||||
//Check if we are connected
|
||||
if(!(db_interface_.connected())) {
|
||||
try {
|
||||
mysqlpp::Query query = db_interface_.query();
|
||||
query << sql;
|
||||
return query.store();
|
||||
} catch(...) {
|
||||
WRN_UH << "not connected to database, reconnecting..." << std::endl;
|
||||
//Try to reconnect
|
||||
try {
|
||||
db_interface_.connect(db_name_.c_str(), db_host_.c_str(), db_user_.c_str(), db_password_.c_str());
|
||||
} catch(...) {
|
||||
ERR_UH << "Could not connect to database: " << db_interface_.error() << std::endl;
|
||||
throw error("Could not connect to database.");
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// Execute the query again
|
||||
mysqlpp::Query query = db_interface_.query();
|
||||
query << sql;
|
||||
return query.store();
|
||||
@ -246,6 +243,7 @@ mysqlpp::Result fuh::db_query(const std::string& sql) {
|
||||
throw error("Error querying database.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string fuh::db_query_to_string(const std::string& query) {
|
||||
return std::string(db_query(query).at(0).at(0));
|
||||
|
Loading…
x
Reference in New Issue
Block a user