本文整理汇总了C++中DBQuery::reset方法的典型用法代码示例。如果您正苦于以下问题:C++ DBQuery::reset方法的具体用法?C++ DBQuery::reset怎么用?C++ DBQuery::reset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBQuery
的用法示例。
在下文中一共展示了DBQuery::reset方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadAccount
Account IOAccount::loadAccount(const std::string& accountName, bool preLoad /* = false*/)
{
Account acc;
acc.name = accountName;
if(g_game.onAccountLogin(
acc.name, acc.number, acc.password,
acc.premiumEnd, acc.warnings, acc.charList)){
//handled by script
return acc;
}
DatabaseDriver* db = DatabaseDriver::instance();
DBQuery query;
DBResult_ptr result;
query << "SELECT `id`, `name`, `password`, `premend`, `warnings` FROM `accounts` WHERE `name` = " << db->escapeString(accountName);
if(!(result = db->storeQuery(query))){
return acc;
}
acc.number = result->getDataInt("id");
acc.password = result->getDataString("password");
acc.premiumEnd = result->getDataInt("premend");
acc.name = result->getDataString("name");
acc.warnings = result->getDataInt("warnings");
if(preLoad)
return acc;
query.reset();
query << "SELECT " <<
"`players`.`name` AS `name`, `worlds`.`name` AS `world`, " <<
"`worlds`.`port` AS `port`, `worlds`.`ip` AS `ip`, `worlds`.`id` AS `world_id`" <<
"FROM `players` " <<
"LEFT JOIN `worlds` ON `worlds`.`id` = `players`.`world_id` " <<
"WHERE `account_id` = " << acc.number;
for(result = db->storeQuery(query); result; result = result->advance()) {
AccountCharacter c;
c.name = result->getDataString("name");
c.world_name = result->getDataString("world");
c.world_id = (uint16_t)result->getDataInt("world_id");
c.port = (uint16_t)result->getDataInt("port");
c.ip = (uint32_t)result->getDataLong("ip");
acc.charList.push_back(c);
}
acc.charList.sort(predicateAccountCharactersByName);
return acc;
}
示例2: executeQuery
bool Database::executeQuery(DBQuery &q)
{
if(!m_initialized || !m_connected)
return false;
std::string s = q.str();
const char* querytext = s.c_str();
int querylength = s.length(); //strlen(querytext);
// Execute the query
if(mysql_real_query(&m_handle, querytext, querylength))
{
//throw DBError( q.getText() , DB_ERROR_QUERY );
std::cout << "MYSQL ERROR mysql_real_query: " << q.str() << " " << mysql_error(&m_handle) << std::endl;
return false;
}
// All is ok
q.reset();
return true;
}
示例3: saveBans
bool IOBanSQL::saveBans(const std::string& identifier, const Ban& banclass)
{
Database db;
if(!db.connect(m_db.c_str(), m_host.c_str(), m_user.c_str(), m_pass.c_str())){
return false;
}
DBQuery query;
query << "BEGIN;";
if(!db.executeQuery(query))
return false;
query << "DELETE FROM bans;";
if(!db.executeQuery(query))
return false;
uint32_t currentTime = std::time(NULL);
//save ip bans
bool executeQuery = false;
query.reset();
query << "INSERT INTO `bans` (`type` , `ip` , `mask`, `time`) VALUES ";
for(IpBanList::const_iterator it = banclass.ipBanList.begin(); it != banclass.ipBanList.end(); ++it){
if(it->time > currentTime){
executeQuery = true;
query << query.getSeparator() << "(1," << it->ip << "," << it->mask <<
"," << it->time << ")";
}
}
if(executeQuery){
if(!db.executeQuery(query))
return false;
}
//save player bans
executeQuery = false;
query.reset();
query << "INSERT INTO `bans` (`type` , `player` , `time`) VALUES ";
for(PlayerBanList::const_iterator it = banclass.playerBanList.begin(); it != banclass.playerBanList.end(); ++it){
if(it->time > currentTime){
executeQuery = true;
query << query.getSeparator() << "(2," << it->id << "," << it->time << ")";
}
}
if(executeQuery){
if(!db.executeQuery(query))
return false;
}
//save account bans
executeQuery = false;
query.reset();
query << "INSERT INTO `bans` (`type` , `account` , `time`) VALUES ";
for(AccountBanList::const_iterator it = banclass.accountBanList.begin(); it != banclass.accountBanList.end(); ++it){
if(it->time > currentTime){
executeQuery = true;
query << query.getSeparator() << "(3," << it->id << "," << it->time << ")";
}
}
if(executeQuery){
if(!db.executeQuery(query))
return false;
}
query.reset();
query << "COMMIT;";
if(!db.executeQuery(query))
return false;
return true;
}
示例4: addPlayerDeath
bool IOPlayer::addPlayerDeath(Player* dying_player, const DeathList& dlist)
{
DatabaseDriver* db = DatabaseDriver::instance();
DBQuery query;
DBTransaction transaction(db);
transaction.begin();
// First insert the actual death
{
DBInsert death_stmt(db);
death_stmt.setQuery("INSERT INTO `player_deaths` (`player_id`, `date`, `level`) VALUES ");
query.reset();
query << dying_player->getGUID() << ", " << std::time(NULL) << " , " << dying_player->getLevel();
if(!death_stmt.addRow(query.str()))
return false;
if(!death_stmt.execute())
return false;
}
uint64_t death_id = db->getLastInsertedRowID();
// Then insert the killers...
for(DeathList::const_iterator dli = dlist.begin(); dli != dlist.end(); ++dli){
DBInsert killer_stmt(db);
killer_stmt.setQuery("INSERT INTO `killers` (`death_id`, `final_hit`) VALUES ");
query.reset();
query << death_id << ", " << (dli == dlist.begin()? 1 : 0);
if(!killer_stmt.addRow(query.str()))
return false;
if(!killer_stmt.execute())
return false;
uint64_t kill_id = db->getLastInsertedRowID();
const DeathEntry& de = *dli;
std::string name;
if(de.isCreatureKill()){
Creature* c = de.getKillerCreature();
Player* player = c->getPlayer();
if(c->isPlayerSummon()){
// Set player, next it will insert GUID
player = c->getPlayerMaster();
// Set name, so the environment insert happens
name = c->getNameDescription();
}
if(player){
//reset unjust kill cache
UnjustCacheMap::iterator it = unjustKillCacheMap.find(player->getGUID());
if(it != unjustKillCacheMap.end()){
unjustKillCacheMap.erase(it);
}
DBInsert player_killers_stmt(db);
player_killers_stmt.setQuery("INSERT INTO `player_killers` (`kill_id`, `player_id`, `unjustified`) VALUES ");
query.reset();
query << kill_id << ", " << player->getGUID() << ", " << (de.isUnjustKill() ? 1 : 0);
if(!player_killers_stmt.addRow(query.str()))
return false;
if(!player_killers_stmt.execute())
return false;
}
else{ // Kill wasn't player, store name so next insert catches it
name = c->getNameDescription();
}
}
else{ // Not a creature kill
name = de.getKillerName();
}
if(name.size() > 0){
DBInsert env_killers_stmt(db);
env_killers_stmt.setQuery("INSERT INTO `environment_killers` (`kill_id`, `name`) VALUES ");
query.reset();
query << kill_id << ", " << db->escapeString(name);
if(!env_killers_stmt.addRow(query.str()))
return false;
if(!env_killers_stmt.execute())
return false;
}
}
return transaction.commit();
}
示例5: loadPlayer
//.........这里部分代码省略.........
// you need to set the vocation after conditions in order to ensure the proper regeneration rates for the vocation
player->setVocation(result->getDataInt("vocation"));
// this stuff has to go after the vocation is set
player->mana = result->getDataInt("mana");
player->manaMax = result->getDataInt("manamax");
player->magLevel = result->getDataInt("maglevel");
uint32_t nextManaCount = (uint32_t)player->vocation->getReqMana(player->magLevel + 1);
uint32_t manaSpent = (uint32_t)result->getDataInt("manaspent");
if(manaSpent > nextManaCount){
//make sure its not out of bound
manaSpent = 0;
}
player->manaSpent = manaSpent;
player->magLevelPercent = Player::getPercentLevel(player->manaSpent, nextManaCount);
player->setLossPercent(LOSS_EXPERIENCE, result->getDataInt("loss_experience"));
player->setLossPercent(LOSS_MANASPENT, result->getDataInt("loss_mana"));
player->setLossPercent(LOSS_SKILLTRIES, result->getDataInt("loss_skills"));
player->setLossPercent(LOSS_ITEMS, result->getDataInt("loss_items"));
player->setLossPercent(LOSS_CONTAINERS, result->getDataInt("loss_containers"));
player->loginPosition.x = result->getDataInt("posx");
player->loginPosition.y = result->getDataInt("posy");
player->loginPosition.z = result->getDataInt("posz");
// login position is temple position
Position loginPos = player->loginPosition;
if(loginPos.x == 0 && loginPos.y == 0 && loginPos.z == 0){
player->loginPosition = player->masterPos;
}
query.reset();
query <<
"SELECT "
" `guild_ranks`.`name` as `rank`, `guild_ranks`.`guild_id` as `guildid`, "
" `guild_ranks`.`level` as `level`, `guilds`.`name` as `guildname`, "
" `guild_members`.`nick` AS `nick` "
"FROM `guild_members` "
"LEFT JOIN `guild_ranks` ON `guild_ranks`.`id` = `guild_members`.`rank_id` "
"LEFT JOIN `guilds` ON `guilds`.`id` = `guild_ranks`.`guild_id` "
"WHERE `guild_members`.`player_id` = " << player->getGUID();
if((result = db->storeQuery(query))){
player->guildName = result->getDataString("guildname");
player->guildLevel = result->getDataInt("level");
player->guildId = result->getDataInt("guildid");
player->guildRank = result->getDataString("rank");
player->guildNick = result->getDataString("nick");
}
//get password
query.reset();
query << "SELECT `password`, `premend` FROM `accounts` WHERE `id` = " << player->accountId;
if(!(result = db->storeQuery(query))){
return false;
}
player->password = result->getDataString("password");
player->premiumDays = IOAccount::getPremiumDaysLeft(result->getDataInt("premend"));
// we need to find out our skills
// so we query the skill table
query.reset();
query << "SELECT `skill_id`, `value`, `count` FROM `player_skills` WHERE `player_id` = " << player->getGUID();
示例6: savePlayer
bool IOPlayer::savePlayer(Player* player, bool shallow)
{
player->preSave();
DatabaseDriver* db = DatabaseDriver::instance();
DBQuery query;
DBResult_ptr result;
//check if the player has to be saved or not
query << "SELECT `save` FROM `players` WHERE `id` = " << player->getGUID();
if(!(result = db->storeQuery(query))){
return false;
}
const uint32_t save = result->getDataInt("save");
if(save == 0)
return true;
//serialize conditions
PropWriteStream propWriteStream;
for(ConditionList::const_iterator it = player->conditions.begin(); it != player->conditions.end(); ++it){
if((*it)->isPersistent()){
if(!(*it)->serialize(propWriteStream)){
return false;
}
propWriteStream.ADD_UCHAR(*CONDITIONATTR_END);
}
}
uint32_t conditionsSize;
const char* conditions = propWriteStream.getStream(conditionsSize);
//First, an UPDATE query to write the player itself
query.reset();
query << "UPDATE `players` SET `level` = " << player->level
<< ", `vocation` = " << (int32_t)player->getVocationId()
<< ", `health` = " << player->health
<< ", `healthmax` = " << player->healthMax
<< ", `direction` = " << player->getDirection().value()
<< ", `experience` = " << player->experience
<< ", `lookbody` = " << (int32_t)player->defaultOutfit.lookBody
<< ", `lookfeet` = " << (int32_t)player->defaultOutfit.lookFeet
<< ", `lookhead` = " << (int32_t)player->defaultOutfit.lookHead
<< ", `looklegs` = " << (int32_t)player->defaultOutfit.lookLegs
<< ", `looktype` = " << (int32_t)player->defaultOutfit.lookType
<< ", `lookaddons` = " << (int32_t)player->defaultOutfit.lookAddons
<< ", `maglevel` = " << player->magLevel
<< ", `mana` = " << player->mana
<< ", `manamax` = " << player->manaMax
<< ", `manaspent` = " << player->manaSpent
<< ", `soul` = " << player->soul
<< ", `town_id` = " << player->town
<< ", `posx` = " << player->getLoginPosition().x
<< ", `posy` = " << player->getLoginPosition().y
<< ", `posz` = " << player->getLoginPosition().z
<< ", `cap` = " << player->getCapacity()
<< ", `sex` = " << player->sex.value()
<< ", `conditions` = " << db->escapeBlob(conditions, conditionsSize)
<< ", `loss_experience` = " << (int32_t)player->getLossPercent(LOSS_EXPERIENCE)
<< ", `loss_mana` = " << (int32_t)player->getLossPercent(LOSS_MANASPENT)
<< ", `loss_skills` = " << (int32_t)player->getLossPercent(LOSS_SKILLTRIES)
<< ", `loss_items` = " << (int32_t)player->getLossPercent(LOSS_ITEMS)
<< ", `loss_containers` = " << (int32_t)player->getLossPercent(LOSS_CONTAINERS)
<< ", `stamina` = " << player->stamina;
#ifdef __SKULLSYSTEM__
query << ", `skull_type` = " << (player->getSkull() == SKULL_RED || player->getSkull() == SKULL_BLACK ? player->getSkull().value() : 0);
query << ", `skull_time` = " << player->lastSkullTime;
#endif
query << " WHERE `id` = " << player->getGUID();
DBTransaction transaction(db);
if(!transaction.begin())
return false;
if(!db->executeQuery(query)){
return false;
}
//skills
for(int32_t i = 0; i <= 6; i++){
query.reset();
query << "UPDATE `player_skills` SET `value` = " << player->skills[i][SKILL_LEVEL] << ", `count` = " << player->skills[i][SKILL_TRIES] << " WHERE `player_id` = " << player->getGUID() << " AND `skill_id` = " << i;
if(!db->executeQuery(query)){
return false;
}
}
if(shallow)
return transaction.commit();
// deletes all player-related stuff
/*
query << "DELETE FROM `player_items` WHERE `player_id` = " << player->getGUID();
//.........这里部分代码省略.........