本文整理汇总了C++中DatabaseDriver类的典型用法代码示例。如果您正苦于以下问题:C++ DatabaseDriver类的具体用法?C++ DatabaseDriver怎么用?C++ DatabaseDriver使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DatabaseDriver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: cleanOnlineInfo
bool IOPlayer::cleanOnlineInfo()
{
DatabaseDriver* db = DatabaseDriver::instance();
DBQuery query;
query << "UPDATE `players` SET `online` = 0 WHERE `world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID);
return db->executeQuery(query);
}
示例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;
}
示例3: saveAccount
bool IOAccount::saveAccount(const Account& acc)
{
DatabaseDriver* db = DatabaseDriver::instance();
DBQuery query;
query << "UPDATE `accounts` SET `premend` = " << acc.premiumEnd << ", `warnings` = " << acc.warnings << " WHERE `id` = " << acc.number;
return db->executeQuery(query);
}
示例4: updateLogoutInfo
void IOPlayer::updateLogoutInfo(Player* player)
{
DatabaseDriver* db = DatabaseDriver::instance();
DBQuery query;
query << "UPDATE `players` SET `lastlogout` = " << player->lastLogout
<< ", `online` = 0"
<< " WHERE `id` = " << player->getGUID();
db->executeQuery(query);
}
示例5: 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);
}
示例6: 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;
}
示例7: 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;
}
示例8: 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;
}
示例9: 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;
}
示例10: 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;
}
示例11: 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;
}
示例12: 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;
}
示例13: 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;
}
示例14: 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;
}
示例15: 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;
}