List:MySQL++« Previous MessageNext Message »
From:Denis Nagorny Date:April 13 2009 6:30am
Subject:mysql++'s connection hangs after long timeout
View as plain text  
Hi all,

I have strange (at least for me) situation.  I ask single field from table
with two columns (id and enabled) in the following manner: "select enabled
from customer where id = " << id;
My server (you can see sources below) works properly during work week and
returns attribute he found.
There are no any requests during weekend but after weekend my server decides
that there are no such records (they are - I'm checked 3 times :)
I'm testing connected() state and trying to reconnect if it disconnected -
It doesn't help. It looks like connection established but records not found.

Has anybody met such situation? Point me proper direction to find the
solution please.

#include <mysql++.h>
#include <boost/date_time/posix_time/posix_time.hpp>
#include "server_config.hpp"
#include "sql.hpp"
sql* sql::instance() {
static sql* retval;
lock lk(sql_mutex);
if(!retval) retval = new sql;
return retval;
}
bool sql::check_if_enabled(long long int id) {
lock lk(sql_mutex);
bool result = false;
try {
if(!conn_.connected()) connect();
mysqlpp::Query query = conn_.query();
query << "select enabled from customer where id = " << id;
mysqlpp::StoreQueryResult ares = query.store();
if(ares.num_rows() > 1) {
std::cerr << "strange client id - more than 1: " << id << std::endl;
result = false;
}
if(ares.num_rows() == 0) {
std::cerr << "unknown client id" << id << std::endl;
result = false;
}
if(ares.num_rows() == 1) {
result = boost::lexical_cast<bool>(ares[0]["enabled"]);
}
}
catch(const mysqlpp::Exception& er) {
std::cerr << "error: " << er.what() << std::endl;
result = true;
}
catch(std::exception& e) {
result = true;
std::cerr << "error: " << e.what() << std::endl;
}
return result;
}
sql::sql():
conn_(false) {
connect();
}
boost::mutex sql::sql_mutex;
void sql::connect() {
if(!conn_.connect(configuration::instance()->database().c_str(),
"127.0.0.1",
configuration::instance()->user_name().c_str(),
configuration::instance()->password().c_str())) {
std::cerr << "Failed to connect to mysql server\n";
}
}

PS Sorry for my English please.

Thread
mysql++'s connection hangs after long timeoutDenis Nagorny13 Apr
  • Re: mysql++'s connection hangs after long timeoutWarren Young13 Apr
    • Re: mysql++'s connection hangs after long timeoutDenis Nagorny14 Apr
    • Re: mysql++'s connection hangs after long timeoutRick Gutleber14 Apr