本文整理汇总了C++中DBResult类的典型用法代码示例。如果您正苦于以下问题:C++ DBResult类的具体用法?C++ DBResult怎么用?C++ DBResult使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DBResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getOfferById
MarketOfferEx IOMarket::getOfferById(uint32_t id)
{
Database* db = Database::getInstance();
DBQuery query;
query << "SELECT `id`, `sale`, `itemtype`, `amount`, `created`, `price`, `player_id`, `anonymous` FROM `market_offers` WHERE `id` = " << id
<< " AND `world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID) << ";";
DBResult* result;
if(!(result = db->storeQuery(query.str())))
return MarketOfferEx();
MarketOfferEx offer;
offer.type = (MarketAction_t)result->getDataInt("sale");
offer.amount = result->getDataInt("amount");
offer.counter = result->getDataInt("id") & 0xFFFF;
offer.timestamp = result->getDataInt("created");
offer.price = result->getDataInt("price");
offer.itemId = result->getDataInt("itemtype");
int32_t playerId = result->getDataInt("player_id");
offer.playerId = playerId;
if(!result->getDataInt("anonymous"))
{
IOLoginData::getInstance()->getNameByGuid(playerId, offer.playerName);
if(offer.playerName.empty())
offer.playerName = "Anonymous";
}
else
offer.playerName = "Anonymous";
result->free();
return offer;
}
示例2: joinGuild
bool IOGuild::joinGuild(Player* player, uint32_t guildId)
{
Database* db = Database::getInstance();
DBQuery query;
DBResult* result;
query << "SELECT `name` FROM `guild_ranks` WHERE `guild_id` = " << guildId << " AND `level` = 1";
if(!(result = db->storeQuery(query.str())))
return false;
const std::string rankName = result->getDataString("name");
query.str("");
db->freeResult(result);
query << "SELECT `name` as `guildname` FROM `guilds` WHERE `id` = " << guildId;
if(!(result = db->storeQuery(query.str())))
return false;
const std::string guildName = result->getDataString("guildname");
query.str("");
db->freeResult(result);
query << "SELECT `id` FROM `guild_ranks` WHERE `guild_id` = " << guildId << " AND `level` = 1";
if(!(result = db->storeQuery(query.str())))
return false;
player->setGuildName(guildName);
player->setGuildId(guildId);
player->setGuildLevel(GUILDLEVEL_MEMBER);
player->setGuildRank(rankName);
player->invitedToGuildsList.clear();
db->freeResult(result);
return true;
}
示例3: canLeaveWar
bool IOGuild::canLeaveWar(uint32_t guildId)
{
if(!isInWar(guildId))
return true;
Database* db = Database::getInstance();
DBQuery query;
DBResult* result;
bool returnVal = true;
query << "SELECT `started` FROM `guild_wars` WHERE `guild1` = " << guildId << " AND `ended` = 0 AND `status` = 1;";
if((result = db->storeQuery(query.str())))
{
do {
if((result->getDataLong("started") + (86400 * 4)) >= time(NULL))
returnVal = false;
} while (result->next());
db->freeResult(result);
}
query.str("");
query << "SELECT `started` FROM `guild_wars` WHERE `guild2` = " << guildId << " AND `ended` = 0 AND `status` = 1;";
if((result = db->storeQuery(query.str())))
{
do {
if((result->getDataLong("started") + (86400 * 4)) >= time(NULL))
returnVal = false;
} while (result->next());
db->freeResult(result);
}
return returnVal;
}
示例4: mysql_init
bool Database::connect()
{
// connection handle initialization
m_handle = mysql_init(nullptr);
if (!m_handle) {
std::cout << std::endl << "Failed to initialize MySQL connection handle." << std::endl;
return false;
}
// automatic reconnect
my_bool reconnect = true;
mysql_options(m_handle, MYSQL_OPT_RECONNECT, &reconnect);
// connects to database
if (!mysql_real_connect(m_handle, g_config.getString(ConfigManager::MYSQL_HOST).c_str(), g_config.getString(ConfigManager::MYSQL_USER).c_str(), g_config.getString(ConfigManager::MYSQL_PASS).c_str(), g_config.getString(ConfigManager::MYSQL_DB).c_str(), g_config.getNumber(ConfigManager::SQL_PORT), nullptr, 0)) {
std::cout << std::endl << "MySQL Error Message: " << mysql_error(m_handle) << std::endl;
return false;
}
m_connected = true;
DBResult* result = storeQuery("SHOW variables LIKE 'max_allowed_packet'");
if (result) {
int32_t max_query = result->getDataInt("Value");
freeResult(result);
if (max_query < 16777216) {
std::cout << std::endl << "[Warning] max_allowed_packet might too low for house item storage" << std::endl;
std::cout << "Use the following query to raise max_allow_packet: ";
std::cout << "SET GLOBAL max_allowed_packet = 16777216";
}
}
return true;
}
示例5: isAccountBanned
bool IOBan::isAccountBanned(uint32_t accountId, BanInfo& banInfo)
{
Database* db = Database::getInstance();
std::ostringstream query;
query << "SELECT `reason`, `expires_at`, `banned_at`, `banned_by`, (SELECT `name` FROM `players` WHERE `id` = `banned_by`) AS `name` FROM `account_bans` WHERE `account_id` = " << accountId;
DBResult* result = db->storeQuery(query.str());
if (!result) {
return false;
}
int64_t expiresAt = result->getNumber<int64_t>("expires_at");
if (expiresAt != 0 && time(nullptr) > expiresAt) {
// Move the ban to history if it has expired
query.str("");
query << "INSERT INTO `account_ban_history` (`account_id`, `reason`, `banned_at`, `expired_at`, `banned_by`) VALUES (" << accountId << ',' << db->escapeString(result->getDataString("reason")) << ',' << result->getDataInt("banned_at") << ',' << expiresAt << ',' << result->getDataInt("banned_by") << ')';
db->executeQuery(query.str());
query.str("");
query << "DELETE FROM `account_bans` WHERE `account_id` = " << accountId;
db->executeQuery(query.str());
db->freeResult(result);
return false;
}
banInfo.expiresAt = expiresAt;
banInfo.reason = result->getDataString("reason");
banInfo.bannedBy = result->getDataString("name");
db->freeResult(result);
return true;
}
示例6: isIpBanned
bool IOBan::isIpBanned(uint32_t clientip, BanInfo& banInfo)
{
if (clientip == 0) {
return false;
}
Database* db = Database::getInstance();
std::ostringstream query;
query << "SELECT `reason`, `expires_at`, (SELECT `name` FROM `players` WHERE `id` = `banned_by`) AS `name` FROM `ip_bans` WHERE `ip` = " << clientip;
DBResult* result = db->storeQuery(query.str());
if (!result) {
return false;
}
int64_t expiresAt = result->getNumber<int64_t>("expires_at");
if (expiresAt != 0 && time(nullptr) > expiresAt) {
query << "DELETE FROM `ip_bans` WHERE `ip` = " << clientip;
db->executeQuery(query.str());
db->freeResult(result);
return false;
}
banInfo.expiresAt = expiresAt;
banInfo.reason = result->getDataString("reason");
banInfo.bannedBy = result->getDataString("name");
db->freeResult(result);
return true;
}
示例7: DBResult
void *API_resultOK(UINT64 affected, UINT64 insertId, int serverStatus,
const char *message, size_t len, void *opt)
{
DBResult *res = new DBResult(affected, insertId);
res->Ref();
return res;
}
示例8: COUNT
void IOMarket::updateStatistics()
{
Database* db = Database::getInstance();
DBQuery query;
query << "SELECT `sale`, `itemtype`, COUNT(`price`) AS `num`, MIN(`price`) AS `min`, MAX(`price`) AS `max`, SUM(`price`) AS `sum` FROM `market_history` WHERE `state` = "
<< OFFERSTATE_ACCEPTED << " AND `world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID) << " GROUP BY `itemtype`, `sale`;";
DBResult* result;
if(!(result = db->storeQuery(query.str())))
return;
do
{
MarketStatistics* statistics;
if(result->getDataInt("sale") == MARKETACTION_BUY)
statistics = &purchaseStatistics[result->getDataInt("itemtype")];
else
statistics = &saleStatistics[result->getDataInt("itemtype")];
statistics->numTransactions = result->getDataInt("num");
statistics->lowestPrice = result->getDataInt("min");
statistics->totalPrice = result->getDataLong("sum");
statistics->highestPrice = result->getDataInt("max");
}
while(result->next());
result->free();
}
示例9: getGuidByNameEx
bool IOLoginData::getGuidByNameEx(uint32_t& guid, bool& specialVip, std::string& name)
{
Database* db = Database::getInstance();
std::ostringstream query;
query << "SELECT `name`, `id`, `group_id`, `account_id` FROM `players` WHERE `name` = " << db->escapeString(name);
DBResult* result = db->storeQuery(query.str());
if (!result) {
return false;
}
name = result->getDataString("name");
guid = result->getDataInt("id");
Group* group = g_game.getGroup(result->getDataInt("group_id"));
db->freeResult(result);
uint64_t flags;
if (group) {
flags = group->flags;
} else {
flags = 0;
}
specialVip = (0 != (flags & ((uint64_t)1 << PlayerFlag_SpecialVIP)));
return true;
}
示例10: loadHouseInfo
bool IOMapSerialize::loadHouseInfo()
{
Database* db = Database::getInstance();
DBResult* result = db->storeQuery("SELECT `id`, `owner`, `paid`, `warnings` FROM `houses`");
if (!result) {
return false;
}
do {
House* house = Houses::getInstance().getHouse(result->getDataInt("id"));
if (house) {
house->setOwner(result->getDataInt("owner"), false);
house->setPaidUntil(result->getDataInt("paid"));
house->setPayRentWarnings(result->getDataInt("warnings"));
}
} while (result->next());
db->freeResult(result);
result = db->storeQuery("SELECT `house_id`, `listid`, `list` FROM `house_lists`");
if (result) {
do {
House* house = Houses::getInstance().getHouse(result->getDataInt("house_id"));
if (house) {
house->setAccessList(result->getDataInt("listid"), result->getDataString("list"));
}
} while (result->next());
db->freeResult(result);
}
return true;
}
示例11: changeRank
bool IOGuild::changeRank(uint32_t guild, const std::string& oldName, const std::string& newName)
{
Database* db = Database::getInstance();
DBResult* result;
DBQuery query;
query << "SELECT `id` FROM `guild_ranks` WHERE `guild_id` = " << guild << " AND `name` " << db->getStringComparer() << db->escapeString(oldName) << " LIMIT 1";
if(!(result = db->storeQuery(query.str())))
return false;
const uint32_t id = result->getDataInt("id");
result->free();
query.str("");
query << "UPDATE `guild_ranks` SET `name` = " << db->escapeString(newName) << " WHERE `id` = " << id << db->getUpdateLimiter();
if(!db->query(query.str()))
return false;
for(AutoList<Player>::iterator it = Player::autoList.begin(); it != Player::autoList.end(); ++it)
{
if(it->second->getRankId() == id)
it->second->setRankName(newName);
}
return true;
}
示例12: joinGuild
bool IOGuild::joinGuild(Player* player, uint32_t guildId)
{
Database* db = Database::getInstance();
DBQuery query;
DBResult* result;
query << "SELECT `id`, `name` FROM `guild_ranks` WHERE `guild_id` = " << guildId << " AND `level` = 1 LIMIT 1";
if(!(result = db->storeQuery(query.str())))
return false;
query.str("");
player->setGuildRank(result->getDataString("name"));
player->setGuildId(guildId);
query << "UPDATE `players` SET `rank_id` = " << result->getDataInt("id") << " WHERE `id` = " << player->getGUID() << db->getUpdateLimiter();
if(!db->executeQuery(query.str()))
return false;
query.str("");
player->setGuildName(getGuildNameById(guildId));
query << "SELECT `id` FROM `guild_ranks` WHERE `guild_id` = " << guildId << " AND `level` = 1 LIMIT 1;";
if(!(result = db->storeQuery(query.str())))
return false;
player->setGuildLevel(GUILDLEVEL_MEMBER);
player->invitedToGuildsList.clear();
return true;
}
示例13: getWarList
GuildWarList IOGuild::getWarList(uint32_t guildId)
{
GuildWarList guildWarList;
Database* db = Database::getInstance();
DBQuery query;
DBResult* result;
query << "SELECT `guild1` FROM `guild_wars` WHERE `guild2` = " << guildId << " AND `ended` = 0 AND `status` = 1;";
if((result = db->storeQuery(query.str())))
{
do {
guildWarList.push_back(result->getDataInt("guild1"));
} while (result->next());
db->freeResult(result);
}
query.str("");
query << "SELECT `guild2` FROM `guild_wars` WHERE `guild1` = " << guildId << " AND `ended` = 0 AND `status` = 1;";
if((result = db->storeQuery(query.str())))
{
do {
guildWarList.push_back(result->getDataInt("guild2"));
} while (result->next());
db->freeResult(result);
}
return guildWarList;
}
示例14: isPlayerBanished
bool BanManager::isPlayerBanished(const uint32_t& playerId) const
{
Database* db = Database::instance();
DBQuery query;
query <<
"SELECT "
"COUNT(*) AS `count` "
"FROM "
"`bans` "
"WHERE "
"`type` = " << BAN_PLAYER << " AND "
"`value` = " << playerId << " AND "
"`active` = 1 AND "
"(`expires` >= " << std::time(NULL) << " OR `expires` <= 0)";
DBResult* result;
if (!(result = db->storeQuery(query.str())))
{
return false;
}
int t = result->getDataInt("count");
db->freeResult(result);
return t > 0;
}
示例15: getGuidByName
bool IOLoginData::getGuidByName(uint32_t& guid, std::string& name)
{
GuidCacheMap::const_iterator it = guidCacheMap.find(name);
if (it != guidCacheMap.end()) {
name = it->first;
guid = it->second;
return true;
}
Database* db = Database::getInstance();
std::ostringstream query;
query << "SELECT `id`, `name` FROM `players` WHERE `name` = " << db->escapeString(name);
DBResult* result = db->storeQuery(query.str());
if (!result) {
return false;
}
name = result->getDataString("name");
guid = result->getDataInt("id");
db->freeResult(result);
guidCacheMap[name] = guid;
return true;
}