本文整理汇总了C++中CDBConn::ExecuteUpdate方法的典型用法代码示例。如果您正苦于以下问题:C++ CDBConn::ExecuteUpdate方法的具体用法?C++ CDBConn::ExecuteUpdate怎么用?C++ CDBConn::ExecuteUpdate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CDBConn
的用法示例。
在下文中一共展示了CDBConn::ExecuteUpdate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: removeGroup
bool CGroupModel::removeGroup(uint32_t nUserId, uint32_t nGroupId, list<uint32_t>& lsCurUserId)
{
bool bRet = false;
CDBManager* pDBManager = CDBManager::getInstance();
CDBConn* pDBConn = pDBManager->GetDBConn("dffxIMDB_master");
set<uint32_t> setGroupUsers;
if(pDBConn)
{
string strSql = "select creator from IMGroup where id="+int2string(nGroupId);
CResultSet* pResultSet = pDBConn->ExecuteQuery(strSql.c_str());
if(pResultSet)
{
uint32_t nCreator;
while (pResultSet->Next()) {
nCreator = pResultSet->GetInt("creator");
}
if(0 == nCreator || nCreator == nUserId)
{
//设置群组不可用。
strSql = "update IMGroup set status=0 where id="+int2string(nGroupId);
bRet = pDBConn->ExecuteUpdate(strSql.c_str());
}
pResultSet->Clear();
}
if (bRet) {
strSql = "select userId from IMGroupMember where groupId="+int2string(nGroupId);
CResultSet* pResultSet = pDBConn->ExecuteQuery(strSql.c_str());
if(pResultSet)
{
while (pResultSet->Next()) {
uint32_t nId = pResultSet->GetInt("userId");
setGroupUsers.insert(nId);
}
pResultSet->Clear();
}
}
pDBManager->RelDBConn(pDBConn);
}
if(bRet)
{
bRet = removeMember(nGroupId, setGroupUsers, lsCurUserId);
}
return bRet;
}
示例2: insertNewMember
bool CGroupModel::insertNewMember(uint32_t nGroupId, set<uint32_t>& setUsers)
{
bool bRet = false;
uint32_t nUserCnt = (uint32_t)setUsers.size();
if(nGroupId != INVALID_VALUE && nUserCnt > 0)
{
CDBManager* pDBManager = CDBManager::getInstance();
CDBConn* pDBConn = pDBManager->GetDBConn("dffxIMDB_slave");
if (pDBConn)
{
uint32_t nCreated = (uint32_t)time(NULL);
// 获取 已经存在群里的用户
string strClause;
bool bFirst = true;
for (auto it=setUsers.begin(); it!=setUsers.end(); ++it)
{
if(bFirst)
{
bFirst = false;
strClause = int2string(*it);
}
else
{
strClause += ("," + int2string(*it));
}
}
string strSql = "select userId from IMGroupMember where groupId=" + int2string(nGroupId) + " and userId in (" + strClause + ")";
CResultSet* pResultSet = pDBConn->ExecuteQuery(strSql.c_str());
set<uint32_t> setHasUser;
if(pResultSet)
{
while (pResultSet->Next()) {
setHasUser.insert(pResultSet->GetInt("userId"));
}
pResultSet->Clear();
}
else
{
log("no result for sql:%s", strSql.c_str());
}
pDBManager->RelDBConn(pDBConn);
pDBConn = pDBManager->GetDBConn("dffxIMDB_master");
if (pDBConn)
{
CacheManager* pCacheManager = CacheManager::getInstance();
CacheConn* pCacheConn = pCacheManager->GetCacheConn("group_member");
if (pCacheConn)
{
// 设置已经存在群中人的状态
if (!setHasUser.empty())
{
strClause.clear();
bFirst = true;
for (auto it=setHasUser.begin(); it!=setHasUser.end(); ++it) {
if(bFirst)
{
bFirst = false;
strClause = int2string(*it);
}
else
{
strClause += ("," + int2string(*it));
}
}
strSql = "update IMGroupMember set status=0, updated="+int2string(nCreated)+" where groupId=" + int2string(nGroupId) + " and userId in (" + strClause + ")";
pDBConn->ExecuteUpdate(strSql.c_str());
}
strSql = "insert into IMGroupMember(`groupId`, `userId`, `status`, `created`, `updated`) values\
(?,?,?,?,?)";
//插入新成员
auto it = setUsers.begin();
uint32_t nStatus = 0;
uint32_t nIncMemberCnt = 0;
for (;it != setUsers.end();)
{
uint32_t nUserId = *it;
if(setHasUser.find(nUserId) == setHasUser.end())
{
CPrepareStatement* pStmt = new CPrepareStatement();
if (pStmt->Init(pDBConn->GetMysql(), strSql))
{
uint32_t index = 0;
pStmt->SetParam(index++, nGroupId);
pStmt->SetParam(index++, nUserId);
pStmt->SetParam(index++, nStatus);
pStmt->SetParam(index++, nCreated);
pStmt->SetParam(index++, nCreated);
pStmt->ExecuteUpdate();
++nIncMemberCnt;
delete pStmt;
}
else
{
setUsers.erase(it++);
delete pStmt;
continue;
}
//.........这里部分代码省略.........