本文整理汇总了C++中DatabaseDriver::getLastInsertedRowID方法的典型用法代码示例。如果您正苦于以下问题:C++ DatabaseDriver::getLastInsertedRowID方法的具体用法?C++ DatabaseDriver::getLastInsertedRowID怎么用?C++ DatabaseDriver::getLastInsertedRowID使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DatabaseDriver
的用法示例。
在下文中一共展示了DatabaseDriver::getLastInsertedRowID方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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();
}