本文整理汇总了C++中DBQuery类的典型用法代码示例。如果您正苦于以下问题:C++ DBQuery类的具体用法?C++ DBQuery怎么用?C++ DBQuery使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DBQuery类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: triggerExists
bool DatabaseManager::triggerExists(const std::string& triggerName)
{
Database* db = Database::getInstance();
DBQuery query;
switch(db->getDatabaseEngine())
{
case DATABASE_ENGINE_MYSQL:
query << "SELECT `name` FROM `sqlite_master` WHERE `type` = 'trigger' AND `name` = " << db->escapeString(triggerName) << ";";
break;
case DATABASE_ENGINE_SQLITE:
query << "SELECT `TRIGGER_NAME` FROM `information_schema`.`TRIGGERS` WHERE `TRIGGER_SCHEMA` = " << db->escapeString(g_config.getString(ConfigManager::SQLITE_DB)) << " AND `TRIGGER_NAME` = " << db->escapeString(triggerName) << ";";
break;
default:
return false;
}
DBResult* result = db->storeQuery(query.str());
if(!result)
return false;
db->freeResult(result);
return true;
}
示例2: 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());
}
示例3: transaction
bool IOMapSerialize::saveMapBinaryTileBased(Map*)
{
Database* db = Database::getInstance();
//Start the transaction
DBTransaction transaction(db);
if(!transaction.begin())
return false;
DBQuery query;
query << "DELETE FROM `tile_store` WHERE `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 ");
for(HouseMap::iterator it = Houses::getInstance()->getHouseBegin(); it != Houses::getInstance()->getHouseEnd(); ++it)
saveHouseBinaryTileBased(db, stmt, it->second);
query.str("");
if(!stmt.execute())
return false;
//End the transaction
return transaction.commit();
}
示例4: revokeInvite
bool IOGuild::revokeInvite(uint32_t guild, uint32_t guid)
{
Database* db = Database::getInstance();
DBQuery query;
query << "DELETE FROM `guild_invites` WHERE `player_id` = " << guid << " AND `guild_id` = " << guild;
return db->query(query.str());
}
示例5: setGuildNick
bool IOGuild::setGuildNick(uint32_t guid, const std::string& nick)
{
Database* db = Database::getInstance();
DBQuery query;
query << "UPDATE `players` SET `guildnick` = " << db->escapeString(nick) << " WHERE `id` = " << guid << db->getUpdateLimiter();
return db->query(query.str());
}
示例6: loadAccount
Account IOAccount::loadAccount(uint32_t accno)
{
Account acc;
Database* db = Database::instance();
DBQuery query;
DBResult* result;
query << "SELECT `id`, `password`, `premend`, `warnings` FROM `accounts` WHERE `id` = " << accno;
if((result = db->storeQuery(query.str()))){
acc.accnumber = result->getDataInt("id");
acc.password = result->getDataString("password");
acc.premEnd = result->getDataInt("premend");
acc.warnings = result->getDataInt("warnings");
db->freeResult(result);
query.str("");
query << "SELECT `name` FROM `players` WHERE `account_id` = " << accno;
if((result = db->storeQuery(query.str()))){
do {
std::string ss = result->getDataString("name");
acc.charList.push_back(ss.c_str());
} while(result->next());
acc.charList.sort();
db->freeResult(result);
}
}
return acc;
}
示例7: 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;
}
示例8: 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;
}
示例9: clearOldHistory
void IOMarket::clearOldHistory()
{
DBQuery query;
query << "DELETE FROM `market_history` WHERE `inserted` <= " << (time(NULL) - g_config.getNumber(ConfigManager::MARKET_OFFER_DURATION)) << " AND `world_id` = "
<< g_config.getNumber(ConfigManager::WORLD_ID) << ";";
Database::getInstance()->query(query.str());
}
示例10: acceptOffer
void IOMarket::acceptOffer(uint32_t offerId, uint16_t amount)
{
DBQuery query;
query << "UPDATE `market_offers` SET `amount` = `amount` - " << amount << " WHERE `id` = " << offerId << " AND `world_id` = "
<< g_config.getNumber(ConfigManager::WORLD_ID) << ";";
Database::getInstance()->query(query.str());
}
示例11: appendHistory
void IOMarket::appendHistory(uint32_t playerId, MarketAction_t type, uint16_t itemId, uint16_t amount, uint32_t price, time_t timestamp, MarketOfferState_t state)
{
DBQuery query;
query << "INSERT INTO `market_history` (`player_id`, `world_id`, `sale`, `itemtype`, `amount`, `price`, `expires_at`, `inserted`, `state`) VALUES "
<< "(" << playerId << ", " << g_config.getNumber(ConfigManager::WORLD_ID) << ", " << type << ", " << itemId << ", " << amount << ", " << price << ", " << timestamp << ", " << time(NULL) << ", " << state << ");";
Database::getInstance()->query(query.str());
}
示例12: 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;
}
示例13: 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;
}
示例14: setMotd
bool IOGuild::setMotd(uint32_t guildId, std::string newMotd)
{
Database* db = Database::getInstance();
DBQuery query;
query << "UPDATE `guilds` SET `motd` = " << db->escapeString(newMotd) << " WHERE `id` = " << guildId;
return db->executeQuery(query.str());
}
示例15: 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;
}