summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2008-11-15 23:43:05 +0100
committerBjørn Lindeijer <bjorn@lindeijer.nl>2008-11-15 23:43:05 +0100
commit18deefca7ec0a00efdf577de3d05eed0e55177b7 (patch)
treed0af6e128031e4ded7fee57ae0fad8a38655cc33 /src
parent0b920a390e7ffbe77575f0c29c19ac286785929b (diff)
downloadmanaserv-18deefca7ec0a00efdf577de3d05eed0e55177b7.tar.gz
manaserv-18deefca7ec0a00efdf577de3d05eed0e55177b7.tar.bz2
manaserv-18deefca7ec0a00efdf577de3d05eed0e55177b7.tar.xz
manaserv-18deefca7ec0a00efdf577de3d05eed0e55177b7.zip
Properly handle exceptions when opening database
It was throwing a std::string but nobody was dealing with it. The actual problem still needs to be fixed. It seems to be having problems with getting some database version.
Diffstat (limited to 'src')
-rw-r--r--src/account-server/dalstorage.cpp26
-rw-r--r--src/account-server/main-account.cpp12
2 files changed, 17 insertions, 21 deletions
diff --git a/src/account-server/dalstorage.cpp b/src/account-server/dalstorage.cpp
index 940f0ff7..f159d635 100644
--- a/src/account-server/dalstorage.cpp
+++ b/src/account-server/dalstorage.cpp
@@ -46,7 +46,6 @@
#define SUPPORTED_DB_VERSION "1"
-
/**
* Constructor.
*/
@@ -56,7 +55,6 @@ DALStorage::DALStorage()
{
}
-
/**
* Destructor.
*/
@@ -68,7 +66,6 @@ DALStorage::~DALStorage()
delete mDb;
}
-
/**
* Connect to the database and initialize it if necessary.
*
@@ -92,15 +89,14 @@ void DALStorage::open()
// open a connection to the database.
mDb->connect();
- //check database version here
+ // check database version here
std::string dbversion = getWorldStateVar(DB_VERSION_PARAMETER);
if (dbversion != SUPPORTED_DB_VERSION)
{
std::ostringstream errmsg;
errmsg << "Database version is not supported. " <<
- "Needed version: " << SUPPORTED_DB_VERSION << ", current version: " <<
- dbversion;
- LOG_ERROR(errmsg.str());
+ "Needed version: '" << SUPPORTED_DB_VERSION <<
+ "', current version: '" << dbversion << "'";
throw errmsg.str();
}
@@ -108,12 +104,13 @@ void DALStorage::open()
SyncDatabase();
}
catch (const DbConnectionFailure& e) {
- LOG_ERROR("(DALStorage::open #1) Unable to connect to the database: "
- << e.what());
+ std::ostringstream errmsg;
+ errmsg << "(DALStorage::open #1) Unable to connect to the database: "
+ << e.what();
+ throw errmsg.str();
}
}
-
/**
* Disconnect from the database.
*/
@@ -122,7 +119,6 @@ void DALStorage::close()
mDb->disconnect();
}
-
Account *DALStorage::getAccountBySQL(std::string const &query)
{
try {
@@ -204,7 +200,6 @@ Account *DALStorage::getAccountBySQL(std::string const &query)
}
}
-
/**
* Get an account by user name.
*/
@@ -215,7 +210,6 @@ Account *DALStorage::getAccount(std::string const &userName)
return getAccountBySQL(sql.str());
}
-
/**
* Get an account by ID.
*/
@@ -226,7 +220,6 @@ Account *DALStorage::getAccount(int accountID)
return getAccountBySQL(sql.str());
}
-
Character *DALStorage::getCharacterBySQL(std::string const &query, Account *owner)
{
Character *character;
@@ -369,7 +362,6 @@ Character *DALStorage::getCharacterBySQL(std::string const &query, Account *owne
return character;
}
-
/**
* Gets a character by database ID.
*/
@@ -386,6 +378,7 @@ Character *DALStorage::getCharacter(const std::string &name)
sql << "select * from " << CHARACTERS_TBL_NAME << " where name = '" << name << "';";
return getCharacterBySQL(sql.str(), NULL);
}
+
#if 0
/**
* Return the list of all Emails addresses.
@@ -868,7 +861,6 @@ void DALStorage::flush(Account *account)
}
}
-
/**
* Delete an account and its associated data from the database.
*/
@@ -1040,7 +1032,7 @@ std::list<Guild*> DALStorage::getGuildList()
std::list<std::pair<int, int> > members;
for (unsigned int j = 0; j < memberInfo.rows(); ++j)
{
- members.push_back(std::pair<int, int>(toUint(memberInfo(j, 0)), toUint(memberInfo(j, 1))));
+ members.push_back(std::pair<int, int>(toUint(memberInfo(j, 0)), toUint(memberInfo(j, 1))));
}
for (std::list<std::pair<int, int> >::const_iterator i = members.begin();
diff --git a/src/account-server/main-account.cpp b/src/account-server/main-account.cpp
index f203f363..d25fd0bb 100644
--- a/src/account-server/main-account.cpp
+++ b/src/account-server/main-account.cpp
@@ -143,10 +143,14 @@ static void initialize()
LOG_INFO("Using Config File: " << configPath);
LOG_INFO("Using Log File: " << logPath);
- // Open database.
- storage = new DALStorage;
- storage->open();
-
+ // Open database
+ try {
+ storage = new DALStorage;
+ storage->open();
+ } catch (std::string &error) {
+ LOG_FATAL("Error opening the database: " << error);
+ exit(1);
+ }
// --- Initialize the managers
// Initialize the slang's and double quotes filter.