当前位置: 首页>>代码示例>>C++>>正文


C++ DatabaseDriver::storeQuery方法代码示例

本文整理汇总了C++中DatabaseDriver::storeQuery方法的典型用法代码示例。如果您正苦于以下问题:C++ DatabaseDriver::storeQuery方法的具体用法?C++ DatabaseDriver::storeQuery怎么用?C++ DatabaseDriver::storeQuery使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DatabaseDriver的用法示例。


在下文中一共展示了DatabaseDriver::storeQuery方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
开发者ID:HeavenIsLost,项目名称:server,代码行数:52,代码来源:ioaccount.cpp

示例2: getGuidByName

bool IOPlayer::getGuidByName(uint32_t &guid, std::string& name)
{
	GuidCacheMap::iterator it = guidCacheMap.find(name);
	if(it != guidCacheMap.end()){
		name = it->first;
		guid = it->second;
		return true;
	}

	DatabaseDriver* db = DatabaseDriver::instance();
	DBResult_ptr result;
	DBQuery query;

	query <<
		"SELECT `name`, `id` "
		"FROM `players` "
		"WHERE `world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID) << " AND `name` = " << db->escapeString(name);
	if(!(result = db->storeQuery(query)))
		return false;

	name = result->getDataString("name");
	guid = result->getDataInt("id");

	guidCacheMap[name] = guid;
	return true;
}
开发者ID:Pietia10,项目名称:server,代码行数:26,代码来源:ioplayer.cpp

示例3: playerExists

bool IOPlayer::playerExists(std::string name)
{
	DatabaseDriver* db = DatabaseDriver::instance();
	DBResult_ptr result;
	DBQuery query;

	query <<
		"SELECT `id` "
		"FROM `players` "
		"WHERE `players`.`world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID) << " AND `name`= " << db->escapeString(name);
	return db->storeQuery(query);
}
开发者ID:Pietia10,项目名称:server,代码行数:12,代码来源:ioplayer.cpp

示例4: getAccountByName

bool IOPlayer::getAccountByName(std::string& account, const std::string& player_name)
{
	DatabaseDriver* db = DatabaseDriver::instance();
	DBResult_ptr result;
	DBQuery query;

	query << "SELECT `a`.`name` FROM `players` p LEFT JOIN `accounts` a ON `p`.`account_id` = `a`.`id` "
		"WHERE `p`.`world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID) << " AND `p`.`name` = " << db->escapeString(player_name);

	if(!(result = db->storeQuery(query)))
		return false;

	account = result->getDataString("name");
	return true;
}
开发者ID:Pietia10,项目名称:server,代码行数:15,代码来源:ioplayer.cpp

示例5: getPassword

bool IOAccount::getPassword(const std::string& accountName, const std::string& playerName, std::string& password)
{
	DatabaseDriver* db = DatabaseDriver::instance();
	DBQuery query;
	DBResult_ptr result;

	query << "SELECT `accounts`.`password` AS `password` FROM `accounts`, `players` " <<
		"WHERE `accounts`.`name` = " << db->escapeString(accountName) << 
		" AND `accounts`.`id` = `players`.`account_id` AND `players`.`name` = " << db->escapeString(playerName);
	if((result = db->storeQuery(query.str()))){
		password = result->getDataString("password");
		return true;
	}

	return false;
}
开发者ID:HeavenIsLost,项目名称:server,代码行数:16,代码来源:ioaccount.cpp

示例6: getDefaultTown

bool IOPlayer::getDefaultTown(std::string& name, uint32_t& depotId)
{
	DatabaseDriver* db = DatabaseDriver::instance();
	DBResult_ptr result;
	DBQuery query;

	query <<
		"SELECT `town_id` "
		"FROM `players` "
		"WHERE `players`.`world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID) << " AND `name`= " << db->escapeString(name);
	if(!(result = db->storeQuery(query)))
		return false;

	depotId = result->getDataInt("town_id");
	return true;
}
开发者ID:Pietia10,项目名称:server,代码行数:16,代码来源:ioplayer.cpp

示例7: getLastIP

bool IOPlayer::getLastIP(uint32_t& ip, uint32_t guid)
{
	DatabaseDriver* db = DatabaseDriver::instance();
	DBResult_ptr result;

	DBQuery query;
	query <<
		"SELECT `lastip` "
		"FROM `players` "
		"WHERE `world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID) << " AND `id` = " << guid << ";";
	if(!(result = db->storeQuery(query)))
		return false;

	ip = result->getDataInt("lastip");
	return true;
}
开发者ID:Pietia10,项目名称:server,代码行数:16,代码来源:ioplayer.cpp

示例8: hasFlag

bool IOPlayer::hasFlag(PlayerFlags flag, uint32_t guid)
{
	DatabaseDriver* db = DatabaseDriver::instance();
	DBResult_ptr result;

	DBQuery query;
	query <<
		"SELECT `groups`.`flags` AS `flags` "
		"FROM `players` "
		"LEFT JOIN `groups` ON `groups`.`id` = `players`.`group_id` "
		"WHERE `world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID) << " AND `players`.`id` = " << guid;
	if(!(result = db->storeQuery(query)))
		return false;

	uint64_t flags = result->getDataLong("flags");
	return (flags & (1ull << flag)) != 0;
}
开发者ID:Pietia10,项目名称:server,代码行数:17,代码来源:ioplayer.cpp

示例9: getGuildIdByName

bool IOPlayer::getGuildIdByName(uint32_t& guildId, const std::string& guildName)
{
	DatabaseDriver* db = DatabaseDriver::instance();
	DBResult_ptr result;
	DBQuery query;

	query <<
		"SELECT `guilds`.`id` "
		"FROM `guilds` "
		"LEFT JOIN `players` ON `players`.`id` = `guilds`.`owner_id` "
		"WHERE `players`.`world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID) << " AND `guilds`.`name` = " << db->escapeString(guildName);
	if(!(result = db->storeQuery(query)))
		return false;

	guildId = result->getDataInt("id");
	return true;
}
开发者ID:Pietia10,项目名称:server,代码行数:17,代码来源:ioplayer.cpp

示例10: getGuidByNameEx

bool IOPlayer::getGuidByNameEx(uint32_t& guid, bool& specialVip, const std::string& player_name)
{
	DatabaseDriver* db = DatabaseDriver::instance();
	DBResult_ptr result;
	DBQuery query;

	query <<
		"SELECT `players`.`name`, `players`.`id`, `groups`.`flags` AS `flags` "
		"FROM `players` LEFT JOIN `groups` ON `groups`.`id` = `players`.`group_id` "
		"WHERE `players`.`world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID) << " AND `players`.`name`= " << db->escapeString(player_name);
	if(!(result = db->storeQuery(query.str())))
		return false;

	guid = result->getDataInt("id");
	specialVip = (result->getDataLong("flags") & (1ull << PlayerFlag_SpecialVIP)) != 0;
	return true;
}
开发者ID:Pietia10,项目名称:server,代码行数:17,代码来源:ioplayer.cpp

示例11: storeNameByGuid

bool IOPlayer::storeNameByGuid(DatabaseDriver &db, uint32_t guid)
{
	DBQuery query;
	DBResult_ptr result;

	NameCacheMap::iterator it = nameCacheMap.find(guid);
	if(it != nameCacheMap.end())
		return true;

	query << "SELECT `name` FROM `players` WHERE `id` = " << guid;

	if(!(result = db.storeQuery(query)))
		return false;

	nameCacheMap[guid] = result->getDataString("name");
	return true;
}
开发者ID:Pietia10,项目名称:server,代码行数:17,代码来源:ioplayer.cpp

示例12: isPlayerOnlineByAccount

bool IOPlayer::isPlayerOnlineByAccount(uint32_t acc)
{
	DatabaseDriver* db = DatabaseDriver::instance();
	DBResult_ptr result;
	DBQuery query;

	query <<
		"SELECT COUNT(*) AS `co` "
		"FROM `players` "
		"WHERE `players`.`online` = 1 AND `players`.`account_id` = " << acc;
	if(!(result = db->storeQuery(query)))
		return false;

	if(result->getDataInt("co") > 0)
		return true;

	return false;
}
开发者ID:Pietia10,项目名称:server,代码行数:18,代码来源:ioplayer.cpp

示例13: getNameByGuid

bool IOPlayer::getNameByGuid(uint32_t guid, std::string& name)
{
	NameCacheMap::iterator it = nameCacheMap.find(guid);
	if(it != nameCacheMap.end()){
		name = it->second;
		return true;
	}

	DatabaseDriver* db = DatabaseDriver::instance();
	DBQuery query;
	DBResult_ptr result;

	query << "SELECT `name` FROM `players` WHERE `world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID) << " AND `id` = " << guid;

	if(!(result = db->storeQuery(query)))
		return false;

	name = result->getDataString("name");
	nameCacheMap[guid] = name;
	return true;
}
开发者ID:Pietia10,项目名称:server,代码行数:21,代码来源:ioplayer.cpp

示例14: 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();

//.........这里部分代码省略.........
开发者ID:Pietia10,项目名称:server,代码行数:101,代码来源:ioplayer.cpp

示例15: loadPlayer

bool IOPlayer::loadPlayer(Player* player, const std::string& name, bool preload /*= false*/)
{
	DatabaseDriver* db = DatabaseDriver::instance();
	DBQuery query;
	DBResult_ptr result;

	query << "SELECT `players`.`id` AS `id`, `players`.`name` AS `name`, `accounts`.`name` AS `accname`, \
		`account_id`, `sex`, `vocation`, `town_id`, `experience`, `level`, `maglevel`, `health`, \
		`groups`.`name` AS `groupname`, `groups`.`flags` AS `groupflags`, `groups`.`access` AS `access`, \
		`groups`.`maxviplist` AS `maxviplist`, `groups`.`maxdepotitems` AS `maxdepotitems`, `groups`.`violation` AS `violationaccess`, \
		`healthmax`, `mana`, `manamax`, `manaspent`, `soul`, `direction`, `lookbody`, \
		`lookfeet`, `lookhead`, `looklegs`, `looktype`, `lookaddons`, `posx`, `posy`, `posz`, `cap`, \
		`lastlogin`, `lastlogout`, `lastip`, `conditions`, `skull_time`, `skull_type`, `stamina`, \
		`loss_experience`, `loss_mana`, `loss_skills`, `loss_items`, `loss_containers` \
		FROM `players` \
		LEFT JOIN `accounts` ON `account_id` = `accounts`.`id`\
		LEFT JOIN `groups` ON `groups`.`id` = `players`.`group_id` \
		WHERE `world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID) << " AND `players`.`name` = " + db->escapeString(name);

	if(!(result = db->storeQuery(query))){
		return false;
	}

	player->setGUID(result->getDataInt("id"));
	player->accountId = result->getDataInt("account_id");
	player->accountName = result->getDataString("accname");

	player->groupName = result->getDataString("groupname");
	player->accessLevel = result->getDataInt("access");
	player->violationLevel = result->getDataInt("violationaccess");
	player->maxDepotLimit = result->getDataInt("maxdepotitems");
	player->maxVipLimit = result->getDataInt("maxviplist");
	player->setFlags(result->getDataLong("groupflags"));

	if(preload){
		//only loading basic info
		return true;
	}

	// Getting all player properties
	player->setSex((PlayerSex)result->getDataInt("sex"));
	player->setDirection((Direction)result->getDataInt("direction"));
	player->level = std::max((uint32_t)1, (uint32_t)result->getDataInt("level"));

	player->town = result->getDataInt("town_id");
	Town* town = Towns::getInstance()->getTown(player->town);
	if(town){
		player->masterPos = town->getTemplePosition();
	}

	uint64_t currExpCount = Player::getExpForLevel(player->level);
	uint64_t nextExpCount = Player::getExpForLevel(player->level + 1);
	uint64_t experience = (uint64_t)result->getDataLong("experience");
	if(experience < currExpCount || experience  > nextExpCount){
		experience = currExpCount;
	}

	player->experience = experience;
	player->levelPercent = Player::getPercentLevel(player->experience - currExpCount, nextExpCount - currExpCount);
	player->soul = result->getDataInt("soul");
	player->capacity = result->getDataInt("cap");
	player->stamina = result->getDataInt("stamina");
	player->lastLoginSaved = result->getDataInt("lastlogin");
	player->lastLogout = result->getDataInt("lastlogout");

	player->health = result->getDataInt("health");
	player->healthMax = result->getDataInt("healthmax");
	player->defaultOutfit.lookType = result->getDataInt("looktype");
	player->defaultOutfit.lookHead = result->getDataInt("lookhead");
	player->defaultOutfit.lookBody = result->getDataInt("lookbody");
	player->defaultOutfit.lookLegs = result->getDataInt("looklegs");
	player->defaultOutfit.lookFeet = result->getDataInt("lookfeet");
	player->defaultOutfit.lookAddons = result->getDataInt("lookaddons");

	player->currentOutfit = player->defaultOutfit;

#ifdef __SKULLSYSTEM__
	SkullType skullType = SkullType(result->getDataInt("skull_type"));
	int64_t lastSkullTime = result->getDataLong("skull_time");

	if((skullType == SKULL_RED && std::time(NULL) < lastSkullTime + g_config.getNumber(ConfigManager::RED_SKULL_DURATION)) ||
		(skullType == SKULL_BLACK && std::time(NULL) < lastSkullTime + g_config.getNumber(ConfigManager::BLACK_SKULL_DURATION))){
		player->lastSkullTime = lastSkullTime;
		player->skullType = skullType;
	}
#endif

	unsigned long conditionsSize = 0;
	const char* conditions = result->getDataStream("conditions", conditionsSize);
	PropStream propStream;
	propStream.init(conditions, conditionsSize);

	Condition* condition;
	while((condition = Condition::createCondition(propStream))){
		if(condition->unserialize(propStream)){
			player->storedConditionList.push_back(condition);
		}
		else{
			delete condition;
		}
//.........这里部分代码省略.........
开发者ID:Pietia10,项目名称:server,代码行数:101,代码来源:ioplayer.cpp


注:本文中的DatabaseDriver::storeQuery方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。