Beispiel #1
0
 inline void MySqlDataStore::OpenDatabaseConnection(
     mysqlpp::Connection& connection) {
   auto connectionResult = connection.set_option(
     new mysqlpp::ReconnectOption{true});
   if(!connectionResult) {
     BOOST_THROW_EXCEPTION(IO::ConnectException{
       "Unable to set MySQL reconnect option."});
   }
   connectionResult = connection.connect(m_schema.c_str(),
     m_address.GetHost().c_str(), m_username.c_str(), m_password.c_str(),
     m_address.GetPort());
   if(!connectionResult) {
     BOOST_THROW_EXCEPTION(IO::ConnectException{std::string{
       "Unable to connect to MySQL database - "} + connection.error()});
   }
 }
Beispiel #2
0
bool DatabaseStorage::connectToDatabase(mysqlpp::Connection& con)
{
    const char *server = 0;
    try
    {
        if (!con.connect(0, server, USER, PASSWORD))
            return false;
    }
    catch (std::exception& er)
    {
        std::cerr << "Attempt to connect to database - exception was thrown.\n";
        return false;
    }

    mysqlpp::NoExceptions ne(con);
    if (!con.select_db(DATABASE))
        return false;

    return true;
}