本文整理汇总了C++中DBResult::free方法的典型用法代码示例。如果您正苦于以下问题:C++ DBResult::free方法的具体用法?C++ DBResult::free怎么用?C++ DBResult::free使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBResult
的用法示例。
在下文中一共展示了DBResult::free方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadHouses
bool IOMapSerialize::loadHouses()
{
Database* db = Database::getInstance();
DBQuery query;
query << "SELECT * FROM `houses` WHERE `world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID);
DBResult* result;
if(!(result = db->storeQuery(query.str())))
return false;
House* house = NULL;
do
{
if(!(house = Houses::getInstance()->getHouse(result->getDataInt("id"))))
continue;
house->setRentWarnings(result->getDataInt("warnings"));
house->setLastWarning(result->getDataInt("lastwarning"));
house->setPaidUntil(result->getDataInt("paid"));
if(result->getDataInt("clear") == 1)
house->setPendingTransfer(true);
house->setOwner(result->getDataInt("owner"));
if(house->getOwner() && house->hasSyncFlag(House::HOUSE_SYNC_UPDATE))
house->resetSyncFlag(House::HOUSE_SYNC_UPDATE);
}
while(result->next());
result->free();
for(HouseMap::iterator it = Houses::getInstance()->getHouseBegin(); it != Houses::getInstance()->getHouseEnd(); ++it)
{
if(!(house = it->second) || !house->getId() || !house->getOwner())
continue;
query.str("");
query << "SELECT `listid`, `list` FROM `house_lists` WHERE `house_id` = " << house->getId();
query << " AND `world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID);
if(!(result = db->storeQuery(query.str())))
continue;
do
house->setAccessList(result->getDataInt("listid"), result->getDataString("list"));
while(result->next());
result->free();
}
return true;
}
示例2: getOwnHistory
HistoryMarketOfferList IOMarket::getOwnHistory(MarketAction_t action, uint32_t playerId)
{
Database* db = Database::getInstance();
DBQuery query;
query << "SELECT `id`, `itemtype`, `amount`, `price`, `expires_at`, `state` FROM `market_history` WHERE `player_id` = "
<< playerId << " AND `sale` = " << action << " AND `world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID) << ";";
DBResult* result;
if(!(result = db->storeQuery(query.str())))
return HistoryMarketOfferList();
HistoryMarketOfferList offerList;
do
{
HistoryMarketOffer offer;
offer.itemId = result->getDataInt("itemtype");
offer.amount = result->getDataInt("amount");
offer.price = result->getDataInt("price");
offer.timestamp = result->getDataInt("expires_at");
MarketOfferState_t offerState = (MarketOfferState_t)result->getDataInt("state");
if(offerState == OFFERSTATE_ACCEPTEDEX)
offerState = OFFERSTATE_ACCEPTED;
offer.state = offerState;
offerList.push_back(offer);
}
while(result->next());
result->free();
return offerList;
}
示例3: getOwnOffers
MarketOfferList IOMarket::getOwnOffers(MarketAction_t action, uint32_t playerId)
{
Database* db = Database::getInstance();
DBQuery query;
query << "SELECT `id`, `amount`, `price`, `created`, `anonymous`, `itemtype` FROM `market_offers` WHERE `player_id` = "
<< playerId << " AND `sale` = " << action << " AND `world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID) << ";";
DBResult* result;
if(!(result = db->storeQuery(query.str())))
return MarketOfferList();
MarketOfferList offerList;
do
{
MarketOffer offer;
offer.amount = result->getDataInt("amount");
offer.price = result->getDataInt("price");
offer.timestamp = result->getDataInt("created") + g_config.getNumber(ConfigManager::MARKET_OFFER_DURATION);
offer.counter = result->getDataInt("id") & 0xFFFF;
offer.itemId = result->getDataInt("itemtype");
offerList.push_back(offer);
}
while(result->next());
result->free();
return offerList;
}
示例4: updateStatistics
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();
}
示例5: getActiveOffers
MarketOfferList IOMarket::getActiveOffers(MarketAction_t action, uint16_t itemId)
{
Database* db = Database::getInstance();
DBQuery query;
query << "SELECT `id`, `player_id`, `amount`, `price`, `created`, `anonymous` FROM `market_offers` WHERE `sale` = "
<< action << " AND `itemtype` = " << itemId << " AND `world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID) << ";";
DBResult* result;
if(!(result = db->storeQuery(query.str())))
return MarketOfferList();
MarketOfferList offerList;
do
{
MarketOffer offer;
offer.amount = result->getDataInt("amount");
offer.price = result->getDataInt("price");
offer.timestamp = result->getDataInt("created") + g_config.getNumber(ConfigManager::MARKET_OFFER_DURATION);
offer.counter = result->getDataInt("id") & 0xFFFF;
if(!result->getDataInt("anonymous"))
{
IOLoginData::getInstance()->getNameByGuid(result->getDataInt("player_id"), offer.playerName);
if(offer.playerName.empty())
offer.playerName = "Anonymous";
}
else
offer.playerName = "Anonymous";
offerList.push_back(offer);
}
while(result->next());
result->free();
return offerList;
}
示例6: getExpiredOffers
ExpiredMarketOfferList IOMarket::getExpiredOffers(MarketAction_t action)
{
Database* db = Database::getInstance();
DBQuery query;
query << "SELECT `id`, `amount`, `price`, `itemtype`, `player_id` FROM `market_offers` WHERE `sale` = " << action << " AND `created` <= "
<< (time(NULL) - g_config.getNumber(ConfigManager::MARKET_OFFER_DURATION)) << " AND `world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID) << ";";
DBResult* result;
if(!(result = db->storeQuery(query.str())))
return ExpiredMarketOfferList();
ExpiredMarketOfferList offerList;
do
{
ExpiredMarketOffer offer;
offer.id = result->getDataInt("id");
offer.amount = result->getDataInt("amount");
offer.price = result->getDataInt("price");
offer.itemId = result->getDataInt("itemtype");
offer.playerId = result->getDataInt("player_id");
offerList.push_back(offer);
}
while(result->next());
result->free();
return offerList;
}
示例7: updateWar
bool IOGuild::updateWar(War_t& war)
{
Database* db = Database::getInstance();
DBResult* result;
DBQuery query;
query << "SELECT `g`.`name` AS `guild_name`, `e`.`name` AS `enemy_name`, `w`.* FROM `guild_wars` w LEFT JOIN `guilds` g ON `w`.`guild_id` = `g`.`id` LEFT JOIN `guilds` e ON `w`.`enemy_id` = `e`.`id` WHERE `w`.`id` = " << war.war;
if(!(result = db->storeQuery(query.str())))
return false;
war.ids[WAR_GUILD] = result->getDataInt("guild_id");
war.ids[WAR_ENEMY] = result->getDataInt("enemy_id");
war.names[WAR_GUILD] = result->getDataString("guild_name");
war.names[WAR_ENEMY] = result->getDataString("enemy_name");
war.frags[WAR_GUILD] = result->getDataInt("guild_kills");
war.frags[WAR_ENEMY] = result->getDataInt("enemy_kills");
war.frags[war.type]++;
war.limit = result->getDataInt("frags");
war.payment = result->getDataInt("payment");
result->free();
if(war.frags[WAR_GUILD] >= war.limit || war.frags[WAR_ENEMY] >= war.limit)
{
Scheduler::getInstance().addEvent(createSchedulerTask(1000,
boost::bind(&IOGuild::finishWar, this, war, true)));
return true;
}
query.str("");
query << "UPDATE `guild_wars` SET `guild_kills` = " << war.frags[WAR_GUILD] << ", `enemy_kills` = " << war.frags[WAR_ENEMY] << " WHERE `id` = " << war.war;
return db->query(query.str());
}
示例8: 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;
}
示例9: updateAuctions
bool IOMapSerialize::updateAuctions()
{
Database* db = Database::getInstance();
DBQuery query;
time_t now = time(NULL);
query << "SELECT `house_id`, `player_id`, `bid` FROM `house_auctions` WHERE `endtime` < " << now;
DBResult* result;
if(!(result = db->storeQuery(query.str())))
return true;
bool success = true;
House* house = NULL;
do
{
query.str("");
query << "DELETE FROM `house_auctions` WHERE `house_id` = " << result->getDataInt("house_id");
if(!(house = Houses::getInstance()->getHouse(result->getDataInt(
"house_id"))) || !db->query(query.str()))
{
success = false;
continue;
}
house->setOwner(result->getDataInt("player_id"));
Houses::getInstance()->payHouse(house, now, result->getDataInt("bid"));
}
while(result->next());
result->free();
return success;
}
示例10: 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;
}
示例11: joinGuild
bool IOGuild::joinGuild(Player* player, uint32_t guildId, bool creation/* = false*/)
{
Database* db = Database::getInstance();
DBResult* result;
DBQuery query;
query << "SELECT `id` FROM `guild_ranks` WHERE `guild_id` = " << guildId << " AND `level` = " << (creation ? "3" : "1") << " LIMIT 1";
if(!(result = db->storeQuery(query.str())))
return false;
const uint32_t rankId = result->getDataInt("id");
result->free();
std::string guildName;
if(!creation)
{
query.str("");
query << "SELECT `name` FROM `guilds` WHERE `id` = " << guildId << " LIMIT 1";
if(!(result = db->storeQuery(query.str())))
return false;
guildName = result->getDataString("name");
result->free();
}
query.str("");
query << "UPDATE `players` SET `rank_id` = " << rankId << " WHERE `id` = " << player->getGUID() << db->getUpdateLimiter();
if(!db->query(query.str()))
return false;
player->setGuildId(guildId);
GuildLevel_t level = GUILDLEVEL_MEMBER;
if(!creation)
player->setGuildName(guildName);
else
level = GUILDLEVEL_LEADER;
player->setGuildLevel(level, rankId);
player->invitationsList.clear();
return true;
}
示例12: storeQuery
DatabaseMySQL::DatabaseMySQL() :
m_timeoutTask(0)
{
m_connected = false;
if(!mysql_init(&m_handle))
{
std::clog << std::endl << "Failed to initialize MySQL connection handler." << std::endl;
return;
}
uint32_t timeout = g_config.getNumber(ConfigManager::MYSQL_READ_TIMEOUT);
if(timeout)
mysql_options(&m_handle, MYSQL_OPT_READ_TIMEOUT, (const char*)&timeout);
timeout = g_config.getNumber(ConfigManager::MYSQL_WRITE_TIMEOUT);
if(timeout)
mysql_options(&m_handle, MYSQL_OPT_WRITE_TIMEOUT, (const char*)&timeout);
my_bool reconnect = true;
mysql_options(&m_handle, MYSQL_OPT_RECONNECT, &reconnect);
if(!mysql_real_connect(&m_handle, g_config.getString(ConfigManager::SQL_HOST).c_str(), g_config.getString(
ConfigManager::SQL_USER).c_str(), g_config.getString(ConfigManager::SQL_PASS).c_str(), g_config.getString(
ConfigManager::SQL_DB).c_str(), g_config.getNumber(ConfigManager::SQL_PORT), NULL, 0))
{
std::clog << "Failed connecting to database - MYSQL ERROR: " << mysql_error(&m_handle) << " (" << mysql_errno(&m_handle) << ")" << std::endl;
return;
}
m_connected = true;
if(mysql_get_client_version() <= 50019)
//MySQL servers <= 5.0.19 have a bug where MYSQL_OPT_RECONNECT option is reset by mysql_real_connect calls.
//Read this http://dev.mysql.com/doc/refman/5.0/en/mysql-options.html for more information.
std::clog << std::endl << "> WARNING: Outdated MySQL server detected, consider upgrading to a newer version." << std::endl;
timeout = g_config.getNumber(ConfigManager::SQL_KEEPALIVE) * 1000;
if(timeout)
m_timeoutTask = Scheduler::getInstance().addEvent(createSchedulerTask(timeout,
boost::bind(&DatabaseMySQL::keepAlive, this)));
if(!g_config.getBool(ConfigManager::HOUSE_STORAGE))
return;
//we cannot lock mutex here :)
DBResult* result = storeQuery("SHOW variables LIKE 'max_allowed_packet';");
if(!result)
return;
if(result->getDataLong("Value") < 16776192)
std::clog << std::endl << "> WARNING: max_allowed_packet might be set too low for binary map storage." << std::endl
<< "Use the following query to raise max_allow_packet: SET GLOBAL max_allowed_packet = 16776192;" << std::endl;
result->free();
}
示例13: saveHouseItems
bool IOMapSerialize::saveHouseItems(Database* db, House* house)
{
std::string config = asLowerCaseString(g_config.getString(ConfigManager::HOUSE_STORAGE));
if(config == "binary-tilebased")
{
DBQuery query;
query << "DELETE FROM `tile_store` WHERE `house_id` = " << house->getId()
<< " AND `world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID);
if(!db->query(query.str()))
return false;
DBInsert stmt(db);
stmt.setQuery("INSERT INTO `tile_store` (`house_id`, `world_id`, `data`) VALUES ");
return saveHouseBinaryTileBased(db, stmt, house) && stmt.execute();
}
else if(config == "binary")
{
DBQuery query;
query << "DELETE FROM `house_data` WHERE `house_id` = "<< house->getId()
<< " AND `world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID);
if(!db->query(query.str()))
return false;
DBInsert stmt(db);
stmt.setQuery("INSERT INTO `house_data` (`house_id`, `world_id`, `data`) VALUES ");
return saveHouseBinary(db, stmt, house) && stmt.execute();
}
DBQuery query;
query << "DELETE FROM `tile_items` WHERE `tile_id` IN (SELECT `id` FROM `tiles` WHERE `house_id` = "
<< house->getId() << " AND `world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID)
<< ") AND `world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID);
if(!db->query(query.str()))
return false;
query.str("");
query << "DELETE FROM `tiles` WHERE `house_id` = " << house->getId()
<< " AND `world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID);
if(!db->query(query.str()))
return false;
query.str("");
query << "SELECT `id` FROM `tiles` WHERE `world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID) << " ORDER BY `id` DESC LIMIT 1;";
DBResult* result;
if(!(result = db->storeQuery(query.str())))
return false;
uint32_t tileId = result->getDataInt("id") + 1;
result->free();
return saveHouseRelational(db, house, tileId);
}
示例14: guildExists
bool IOGuild::guildExists(uint32_t guild)
{
Database* db = Database::getInstance();
DBResult* result;
DBQuery query;
query << "SELECT `id` FROM `guilds` WHERE `id` = " << guild << " AND `world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID) << " LIMIT 1";
if(!(result = db->storeQuery(query.str())))
return false;
result->free();
return true;
}
示例15: isInvited
bool IOGuild::isInvited(uint32_t guild, uint32_t guid)
{
Database* db = Database::getInstance();
DBResult* result;
DBQuery query;
query << "SELECT `guild_id` FROM `guild_invites` WHERE `player_id` = " << guid << " AND `guild_id`= " << guild << " LIMIT 1";
if(!(result = db->storeQuery(query.str())))
return false;
result->free();
return true;
}