diff options
author | Guillaume Melquiond <guillaume.melquiond@gmail.com> | 2007-08-28 17:03:44 +0000 |
---|---|---|
committer | Guillaume Melquiond <guillaume.melquiond@gmail.com> | 2007-08-28 17:03:44 +0000 |
commit | e678c7cc1574d5739f83da2b0d493b44e3a7a42e (patch) | |
tree | a184372b02622d82bc85a9827a835de186b0e2ed /src/account-server/dalstorage.cpp | |
parent | c4a2cd54d72f776d6e37eae7a8c67caa81269f4f (diff) | |
download | manaserv-e678c7cc1574d5739f83da2b0d493b44e3a7a42e.tar.gz manaserv-e678c7cc1574d5739f83da2b0d493b44e3a7a42e.tar.bz2 manaserv-e678c7cc1574d5739f83da2b0d493b44e3a7a42e.tar.xz manaserv-e678c7cc1574d5739f83da2b0d493b44e3a7a42e.zip |
Implemented quest variables.
Diffstat (limited to 'src/account-server/dalstorage.cpp')
-rw-r--r-- | src/account-server/dalstorage.cpp | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/account-server/dalstorage.cpp b/src/account-server/dalstorage.cpp index e9887fad..612d0565 100644 --- a/src/account-server/dalstorage.cpp +++ b/src/account-server/dalstorage.cpp @@ -184,6 +184,7 @@ void DALStorage::open() createTable(CHANNELS_TBL_NAME, SQL_CHANNELS_TABLE); createTable(GUILDS_TBL_NAME, SQL_GUILDS_TABLE); createTable(GUILD_MEMBERS_TBL_NAME, SQL_GUILD_MEMBERS_TABLE); + createTable(QUESTS_TBL_NAME, SQL_QUESTS_TABLE); } catch (const DbConnectionFailure& e) { LOG_ERROR("(DALStorage::open #1) Unable to connect to the database: " @@ -1231,3 +1232,58 @@ std::list<Guild*> DALStorage::getGuildList() return guilds; } + +std::string DALStorage::getQuestVar(int id, std::string const &name) +{ + // connect to the database (if not connected yet). + open(); + + using namespace dal; + + try + { + std::ostringstream query; + query << "select value from " << QUESTS_TBL_NAME + << " where owner_id = '" << id << "' and name = '" + << name << "';"; + RecordSet const &info = mDb->execSql(query.str()); + + if (!info.isEmpty()) return info(0, 0); + } + catch (DbSqlQueryExecFailure const &e) + { + LOG_ERROR("(DALStorage::getQuestVar) SQL query failure: " << e.what()); + } + + return std::string(); +} + +void DALStorage::setQuestVar(int id, std::string const &name, + std::string const &value) +{ + // connect to the database (if not connected yet). + open(); + + using namespace dal; + + try + { + std::ostringstream query1; + query1 << "delete from " << QUESTS_TBL_NAME + << " where owner_id = '" << id << "' and name = '" + << name << "';"; + mDb->execSql(query1.str()); + + if (value.empty()) return; + + std::ostringstream query2; + query2 << "insert into " << QUESTS_TBL_NAME + << " (owner_id, name, value) values ('" + << id << "', '" << name << "', '" << value << "');"; + mDb->execSql(query2.str()); + } + catch (DbSqlQueryExecFailure const &e) + { + LOG_ERROR("(DALStorage::setQuestVar) SQL query failure: " << e.what()); + } +} |