From d0187a975857ba5cf35b688acd84666cee0ddbb8 Mon Sep 17 00:00:00 2001 From: Yohann Ferreira Date: Wed, 10 Nov 2010 00:12:18 +0100 Subject: Fix code indentation in the sql related files. Trivial fix. --- src/account-server/storage.cpp | 66 ++++++++++++++++++++++----------------- src/dal/dataprovider.cpp | 2 -- src/dal/mysqldataprovider.cpp | 70 ++++++++++++++++++++++-------------------- src/dal/pqdataprovider.cpp | 24 +++++++-------- src/dal/sqlitedataprovider.cpp | 45 +++++++++++++-------------- 5 files changed, 107 insertions(+), 100 deletions(-) diff --git a/src/account-server/storage.cpp b/src/account-server/storage.cpp index 20f9fe5..e741875 100644 --- a/src/account-server/storage.cpp +++ b/src/account-server/storage.cpp @@ -72,7 +72,7 @@ static const char *CHAR_ATTR_TBL_NAME = "mana_char_attr"; static const char *CHAR_SKILLS_TBL_NAME = "mana_char_skills"; static const char *CHAR_STATUS_EFFECTS_TBL_NAME = "mana_char_status_effects"; static const char *CHAR_KILL_COUNT_TBL_NAME = "mana_char_kill_stats"; -static const char *CHAR_SPECIALS_TBL_NAME = "mana_char_specials"; +static const char *CHAR_SPECIALS_TBL_NAME = "mana_char_specials"; static const char *CHAR_EQUIPS_TBL_NAME = "mana_char_equips"; static const char *INVENTORIES_TBL_NAME = "mana_inventories"; static const char *ITEMS_TBL_NAME = "mana_items"; @@ -118,7 +118,8 @@ void Storage::open() using namespace dal; - try { + try + { // open a connection to the database. mDb->connect(); @@ -127,9 +128,9 @@ void Storage::open() if (dbversion != SUPPORTED_DB_VERSION) { std::ostringstream errmsg; - errmsg << "Database version is not supported. " << - "Needed version: '" << SUPPORTED_DB_VERSION << - "', current version: '" << dbversion << "'"; + errmsg << "Database version is not supported. " + << "Needed version: '" << SUPPORTED_DB_VERSION + << "', current version: '" << dbversion << "'"; throw errmsg.str(); } @@ -141,10 +142,11 @@ void Storage::open() sql << "DELETE FROM " << ONLINE_USERS_TBL_NAME; mDb->execSql(sql.str()); } - catch (const DbConnectionFailure& e) { + catch (const DbConnectionFailure& e) + { std::ostringstream errmsg; errmsg << "(DALStorage::open #1) Unable to connect to the database: " - << e.what(); + << e.what(); throw errmsg.str(); } } @@ -164,7 +166,8 @@ void Storage::close() */ Account *Storage::getAccountBySQL() { - try { + try + { const dal::RecordSet &accountInfo = mDb->processSql(); // if the account is not even in the database then @@ -191,7 +194,7 @@ Account *Storage::getAccountBySQL() int level = toUint(accountInfo(0, 4)); // Check if the user is permanently banned, or temporarily banned. if (level == AL_BANNED - || time(0) <= (int) toUint(accountInfo(0, 5))) + || time(0) <= (int) toUint(accountInfo(0, 5))) { account->setLevel(AL_BANNED); // It is, so skip character loading. @@ -293,7 +296,8 @@ Character *Storage::getCharacterBySQL(Account *owner) // a string to an unsigned int. string_to< unsigned > toUint; - try { + try + { const dal::RecordSet &charInfo = mDb->processSql(); // if the character is not even in the database then @@ -528,7 +532,8 @@ Character *Storage::getCharacter(const std::string &name) */ bool Storage::doesUserNameExist(const std::string &name) { - try { + try + { std::ostringstream sql; sql << "SELECT COUNT(username) FROM " << ACCOUNTS_TBL_NAME << " WHERE username = ?"; @@ -543,7 +548,9 @@ bool Storage::doesUserNameExist(const std::string &name) unsigned int iReturn = 1; ssStream >> iReturn; return iReturn != 0; - } catch (const std::exception &e) { + } + catch (const std::exception &e) + { // TODO: throw an exception. LOG_ERROR("(DALStorage::doesUserNameExist) SQL query failure: " << e.what()); } @@ -557,7 +564,8 @@ bool Storage::doesUserNameExist(const std::string &name) */ bool Storage::doesEmailAddressExist(const std::string &email) { - try { + try + { std::ostringstream sql; sql << "SELECT COUNT(email) FROM " << ACCOUNTS_TBL_NAME << " WHERE UPPER(email) = UPPER(?)"; @@ -571,7 +579,9 @@ bool Storage::doesEmailAddressExist(const std::string &email) unsigned int iReturn = 1; ssStream >> iReturn; return iReturn != 0; - } catch (const std::exception &e) { + } + catch (const std::exception &e) + { // TODO: throw an exception. LOG_ERROR("(DALStorage::doesEmailAddressExist) SQL query failure: " << e.what()); } @@ -585,7 +595,8 @@ bool Storage::doesEmailAddressExist(const std::string &email) */ bool Storage::doesCharacterNameExist(const std::string& name) { - try { + try + { std::ostringstream sql; sql << "SELECT COUNT(name) FROM " << CHARACTERS_TBL_NAME << " WHERE name = ?"; if (mDb->prepareSql(sql.str())) @@ -598,7 +609,9 @@ bool Storage::doesCharacterNameExist(const std::string& name) int iReturn = 1; ssStream >> iReturn; return iReturn != 0; - } catch (const std::exception &e) { + } + catch (const std::exception &e) + { // TODO: throw an exception. LOG_ERROR("(DALStorage::doesCharacterNameExist) SQL query failure: " << e.what()); @@ -1131,9 +1144,7 @@ void Storage::updateExperience(int charId, int skillId, int skillValue) // check if the update has modified a row if (mDb->getModifiedRows() > 0) - { return; - } sql.clear(); sql.str(""); @@ -1162,7 +1173,8 @@ void Storage::updateExperience(int charId, int skillId, int skillValue) void Storage::updateAttribute(int charId, unsigned int attrId, double base, double mod) { - try { + try + { std::ostringstream sql; sql << "UPDATE " << CHAR_ATTR_TBL_NAME << " " << "SET " @@ -1320,7 +1332,8 @@ void Storage::addGuildMember(int guildId, int memberId) << 0 << ");"; mDb->execSql(sql.str()); } - catch (const dal::DbSqlQueryExecFailure& e) { + catch (const dal::DbSqlQueryExecFailure& e) + { // TODO: throw an exception. LOG_ERROR("SQL query failure: " << e.what()); } @@ -1435,7 +1448,8 @@ std::list Storage::getGuildList() } } } - catch (const dal::DbSqlQueryExecFailure& e) { + catch (const dal::DbSqlQueryExecFailure& e) + { // TODO: throw an exception. LOG_ERROR("SQL query failure: " << e.what()); } @@ -1552,17 +1566,14 @@ void Storage::setWorldStateVar(const std::string &name, << " WHERE state_name = '" << name << "'"; if (mapId >= 0) - { updateStateVar << " AND map_id = '" << mapId << "'"; - } + updateStateVar << ";"; mDb->execSql(updateStateVar.str()); // if we updated a row, were finished here if (mDb->getModifiedRows() >= 1) - { return; - } // otherwise we have to add the new variable std::ostringstream insertStateVar; @@ -1570,13 +1581,10 @@ void Storage::setWorldStateVar(const std::string &name, << " (state_name, map_id, value , moddate) VALUES (" << "'" << name << "', "; if (mapId >= 0) - { insertStateVar << "'" << mapId << "', "; - } else - { insertStateVar << "0 , "; - } + insertStateVar << "'" << value << "', " << "'" << time(0) << "');"; mDb->execSql(insertStateVar.str()); diff --git a/src/dal/dataprovider.cpp b/src/dal/dataprovider.cpp index 24fe884..684c255 100644 --- a/src/dal/dataprovider.cpp +++ b/src/dal/dataprovider.cpp @@ -89,9 +89,7 @@ bool DataProvider::isConnected() const std::string DataProvider::getDbName() const { if (!isConnected()) - { return ""; - } return mDbName; } diff --git a/src/dal/mysqldataprovider.cpp b/src/dal/mysqldataprovider.cpp index 4e5f286..d0c488a 100644 --- a/src/dal/mysqldataprovider.cpp +++ b/src/dal/mysqldataprovider.cpp @@ -59,9 +59,8 @@ MySqlDataProvider::~MySqlDataProvider() // make sure that the database is closed. // disconnect() calls mysql_close() which takes care of freeing // the memory allocated for the handle. - if (mIsConnected) { + if (mIsConnected) disconnect(); - } } @@ -80,9 +79,8 @@ DbBackends MySqlDataProvider::getDbBackend() const */ void MySqlDataProvider::connect() { - if (mIsConnected) { + if (mIsConnected) return; - } // retrieve configuration from config file const std::string hostname @@ -100,7 +98,8 @@ void MySqlDataProvider::connect() // for mysql_real_connect(). mDb = mysql_init(NULL); - if (!mDb) { + if (!mDb) + { throw DbConnectionFailure( "unable to initialize the MySQL library: no memory"); } @@ -142,48 +141,47 @@ const RecordSet& MySqlDataProvider::execSql(const std::string& sql, const bool refresh) { - if (!mIsConnected) { + if (!mIsConnected) throw std::runtime_error("not connected to database"); - } - LOG_DEBUG("MySqlDataProvider::execSql Performing SQL query: "< 0) { + if (mysql_field_count(mDb) > 0) + { MYSQL_RES* res; // get the result of the query. - if (!(res = mysql_store_result(mDb))) { + if (!(res = mysql_store_result(mDb))) throw DbSqlQueryExecFailure(mysql_error(mDb)); - } // set the field names. unsigned int nFields = mysql_num_fields(res); MYSQL_FIELD* fields = mysql_fetch_fields(res); Row fieldNames; - for (unsigned int i = 0; i < nFields; ++i) { + for (unsigned int i = 0; i < nFields; ++i) fieldNames.push_back(fields[i].name); - } + mRecordSet.setColumnHeaders(fieldNames); // populate the RecordSet. MYSQL_ROW row; - while ((row = mysql_fetch_row(res))) { + while ((row = mysql_fetch_row(res))) + { Row r; - for (unsigned int i = 0; i < nFields; ++i) { + for (unsigned int i = 0; i < nFields; ++i) r.push_back(static_cast(row[i])); - } mRecordSet.add(r); } @@ -202,9 +200,8 @@ MySqlDataProvider::execSql(const std::string& sql, */ void MySqlDataProvider::disconnect() { - if (!mIsConnected) { + if (!mIsConnected) return; - } // mysql_close() closes the connection and deallocates the connection // handle allocated by mysql_init(). @@ -332,7 +329,8 @@ unsigned MySqlDataProvider::getModifiedRows() const const my_ulonglong affected = mysql_affected_rows(mDb); if (affected > INT_MAX) - throw std::runtime_error("MySqlDataProvider::getLastId exceeded INT_MAX"); + throw std::runtime_error( + "MySqlDataProvider::getLastId exceeded INT_MAX"); if (affected == (my_ulonglong)-1) { @@ -397,17 +395,20 @@ const RecordSet &MySqlDataProvider::processSql() if (mysql_stmt_bind_param(mStmt, paramsBind)) { - LOG_ERROR("MySqlDataProvider::processSql Bind params failed: " << mysql_stmt_error(mStmt)); + LOG_ERROR("MySqlDataProvider::processSql Bind params failed: " + << mysql_stmt_error(mStmt)); } - if (mysql_stmt_field_count(mStmt) > 0) { + if (mysql_stmt_field_count(mStmt) > 0) + { mRecordSet.clear(); MYSQL_BIND* resultBind; MYSQL_RES* res; if (mysql_stmt_execute(mStmt)) { - LOG_ERROR("MySqlDataProvider::processSql Execute failed: " << mysql_stmt_error(mStmt)); + LOG_ERROR("MySqlDataProvider::processSql Execute failed: " + << mysql_stmt_error(mStmt)); } res = mysql_stmt_result_metadata(mStmt); @@ -419,7 +420,8 @@ const RecordSet &MySqlDataProvider::processSql() resultBind = new MYSQL_BIND[mysql_num_fields(res)]; - for (i = 0; i < mysql_num_fields(res); ++i) { + for (i = 0; i < mysql_num_fields(res); ++i) + { resultBind[i].buffer_type = MYSQL_TYPE_STRING; resultBind[i].buffer = (void*) new char[255]; resultBind[i].buffer_length = 255; @@ -430,26 +432,26 @@ const RecordSet &MySqlDataProvider::processSql() if (mysql_stmt_bind_result(mStmt, resultBind)) { - LOG_ERROR("MySqlDataProvider::processSql Bind result failed: " << mysql_stmt_error(mStmt)); + LOG_ERROR("MySqlDataProvider::processSql Bind result failed: " + << mysql_stmt_error(mStmt)); } - for (i = 0; i < nFields; ++i) { + for (i = 0; i < nFields; ++i) fieldNames.push_back(fields[i].name); - } + mRecordSet.setColumnHeaders(fieldNames); // store the result of the query. - if (mysql_stmt_store_result(mStmt)) { + if (mysql_stmt_store_result(mStmt)) throw DbSqlQueryExecFailure(mysql_stmt_error(mStmt)); - } // populate the RecordSet. - while (!mysql_stmt_fetch(mStmt)) { + while (!mysql_stmt_fetch(mStmt)) + { Row r; - for (unsigned int i = 0; i < nFields; ++i) { + for (unsigned int i = 0; i < nFields; ++i) r.push_back(static_cast(resultBind[i].buffer)); - } mRecordSet.add(r); } diff --git a/src/dal/pqdataprovider.cpp b/src/dal/pqdataprovider.cpp index dfe5253..5351b0c 100644 --- a/src/dal/pqdataprovider.cpp +++ b/src/dal/pqdataprovider.cpp @@ -41,9 +41,8 @@ PqDataProvider::PqDataProvider() PqDataProvider::~PqDataProvider() throw() { - if (mIsConnected) { + if (mIsConnected) disconnect(); - } } @@ -94,18 +93,19 @@ void PqDataProvider::connect(const std::string& dbName, const RecordSet &PqDataProvider::execSql(const std::string& sql, const bool refresh) { - if (!mIsConnected) { + if (!mIsConnected) throw std::runtime_error("not connected to database"); - } - if (refresh || (sql != mSql)) { + if (refresh || (sql != mSql)) + { mRecordSet.clear(); // execute the query PGresult *res; res = PQexec(mDb, sql.c_str()); - if (PQresultStatus(res) != PGRES_COMMAND_OK) { + if (PQresultStatus(res) != PGRES_COMMAND_OK) + { PQclear(res); throw DbSqlQueryExecFailure(PQerrorMessage(mDb)); } @@ -115,18 +115,19 @@ const RecordSet &PqDataProvider::execSql(const std::string& sql, // fill column names Row fieldNames; - for (unsigned int i = 0; i < nFields; i++) { + for (unsigned int i = 0; i < nFields; i++) + { fieldNames.push_back(PQfname(res, i)); } mRecordSet.setColumnHeaders(fieldNames); // fill rows - for (unsigned int r = 0; r < PQntuples(res); r++) { + for (unsigned int r = 0; r < PQntuples(res); r++) + { Row row; - for (unsigned int i = 0; i < nFields; i++) { + for (unsigned int i = 0; i < nFields; i++) row.push_back(PQgetvalue(res, r, i)); - } mRecordSet.add(row); } @@ -143,9 +144,8 @@ const RecordSet &PqDataProvider::execSql(const std::string& sql, */ void PqDataProvider::disconnect() { - if (!mIsConnected) { + if (!mIsConnected) return; - } // finish up with Postgre. PQfinish(mDb); diff --git a/src/dal/sqlitedataprovider.cpp b/src/dal/sqlitedataprovider.cpp index 12ab2de..ea394e0 100644 --- a/src/dal/sqlitedataprovider.cpp +++ b/src/dal/sqlitedataprovider.cpp @@ -50,15 +50,16 @@ SqLiteDataProvider::SqLiteDataProvider() SqLiteDataProvider::~SqLiteDataProvider() throw() { - try { + try + { // make sure that the database is closed. // disconnect() calls sqlite3_close() which takes care of freeing // the memory allocated for the handle. - if (mIsConnected) { + if (mIsConnected) disconnect(); - } } - catch (...) { + catch (...) + { // ignore } } @@ -89,7 +90,8 @@ SqLiteDataProvider::connect() // sqlite3_open creates the database file if it does not exist // as a side-effect. - if (sqlite3_open(dbName.c_str(), &mDb) != SQLITE_OK) { + if (sqlite3_open(dbName.c_str(), &mDb) != SQLITE_OK) + { // save the error message thrown by sqlite3_open() // as we may lose it when sqlite3_close() runs. std::string msg(sqlite3_errmsg(mDb)); @@ -120,16 +122,16 @@ const RecordSet& SqLiteDataProvider::execSql(const std::string& sql, const bool refresh) { - if (!mIsConnected) { + if (!mIsConnected) throw std::runtime_error("not connected to database"); - } - LOG_DEBUG("Performing SQL query: "<