Skip to content

Commit 2be9125

Browse files
committed
modify:can be delete userkey and timerelease datas when delete table
1 parent 11e9169 commit 2be9125

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

XEngine_Source/MQCore_DBModule/DBModule_MQUser/DBModule_MQUser.cpp

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -519,13 +519,23 @@ BOOL CDBModule_MQUser::DBModule_MQUser_KeyDelete(XENGINE_DBUSERKEY* pSt_UserKey)
519519
TCHAR tszSQLStatement[1024];
520520
memset(tszSQLStatement, '\0', sizeof(tszSQLStatement));
521521

522-
if (_tcslen(pSt_UserKey->tszKeyName) <= 0)
522+
if ((_tcslen(pSt_UserKey->tszKeyName) > 0) && (_tcslen(pSt_UserKey->tszUserName) > 0))
523+
{
524+
_stprintf_s(tszSQLStatement, _T("DELETE FROM `UserKey` WHERE tszKeyUser = '%s' AND tszKeyName = '%s'"), pSt_UserKey->tszUserName, pSt_UserKey->tszKeyName);
525+
}
526+
else if ((_tcslen(pSt_UserKey->tszKeyName) > 0) && (_tcslen(pSt_UserKey->tszUserName) <= 0))
527+
{
528+
_stprintf_s(tszSQLStatement, _T("DELETE FROM `UserKey` WHERE tszKeyName = '%s'"), pSt_UserKey->tszKeyName);
529+
}
530+
else if ((_tcslen(pSt_UserKey->tszKeyName) <= 0) && (_tcslen(pSt_UserKey->tszUserName) > 0))
523531
{
524532
_stprintf_s(tszSQLStatement, _T("DELETE FROM `UserKey` WHERE tszKeyUser = '%s'"), pSt_UserKey->tszUserName);
525533
}
526534
else
527535
{
528-
_stprintf_s(tszSQLStatement, _T("DELETE FROM `UserKey` WHERE tszKeyUser = '%s' AND tszKeyName = '%s'"), pSt_UserKey->tszUserName, pSt_UserKey->tszKeyName);
536+
DBModule_IsErrorOccur = TRUE;
537+
DBModule_dwErrorCode = ERROR_XENGINE_MQCORE_DATABASE_PARAMENT;
538+
return FALSE;
529539
}
530540

531541
if (!DataBase_MySQL_Execute(xhDBSQL, tszSQLStatement))
@@ -730,7 +740,21 @@ BOOL CDBModule_MQUser::DBModule_MQUser_TimeDelete(XENGINE_DBTIMERELEASE* pSt_DBI
730740
TCHAR tszSQLQuery[2048];
731741
memset(tszSQLQuery, '\0', sizeof(tszSQLQuery));
732742

733-
_stprintf_s(tszSQLQuery, _T("DELETE FROM `UserTime` WHERE nIDMsg = %lld"), pSt_DBInfo->nIDMsg);
743+
if (pSt_DBInfo->nIDMsg > 0)
744+
{
745+
_stprintf_s(tszSQLQuery, _T("DELETE FROM `UserTime` WHERE nIDMsg = %lld"), pSt_DBInfo->nIDMsg);
746+
}
747+
else if (_tcslen(pSt_DBInfo->tszQueueName) > 0)
748+
{
749+
_stprintf_s(tszSQLQuery, _T("DELETE FROM `UserTime` WHERE tszQueueName = '%s'"), pSt_DBInfo->tszQueueName);
750+
}
751+
else
752+
{
753+
DBModule_IsErrorOccur = TRUE;
754+
DBModule_dwErrorCode = ERROR_XENGINE_MQCORE_DATABASE_PARAMENT;
755+
return FALSE;
756+
}
757+
734758
if (!DataBase_MySQL_Execute(xhDBSQL, tszSQLQuery))
735759
{
736760
DBModule_IsErrorOccur = TRUE;

XEngine_Source/XEngine_MQServiceApp/MQService_TCPTask.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,10 +522,17 @@ BOOL MessageQueue_TCP_Handle(XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, LPCTSTR lpszC
522522
pSt_ProtocolHdr->unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_MQ_REPDELETE;
523523
//清理所有者
524524
XENGINE_DBTOPICOWNER st_DBOwner;
525+
XENGINE_DBUSERKEY st_UserKey;
526+
XENGINE_DBTIMERELEASE st_DBInfo;
527+
525528
memset(&st_DBOwner, '\0', sizeof(XENGINE_DBTOPICOWNER));
529+
memset(&st_UserKey, '\0', sizeof(XENGINE_DBUSERKEY));
530+
memset(&st_DBInfo, '\0', sizeof(XENGINE_DBTIMERELEASE));
526531

527532
_tcscpy(st_DBOwner.tszUserName, tszUserName);
528533
_tcscpy(st_DBOwner.tszQueueName, st_MQProtocol.tszMQKey);
534+
_tcscpy(st_UserKey.tszKeyName, st_MQProtocol.tszMQKey);
535+
_tcscpy(st_DBInfo.tszQueueName, st_MQProtocol.tszMQKey);
529536

530537
if (!DBModule_MQUser_OwnerDelete(&st_DBOwner))
531538
{
@@ -541,6 +548,8 @@ BOOL MessageQueue_TCP_Handle(XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, LPCTSTR lpszC
541548
//清楚数据库
542549
SessionModule_Notify_Destory(st_MQProtocol.tszMQKey);
543550
DBModule_MQData_DeleteTable(st_MQProtocol.tszMQKey);
551+
DBModule_MQUser_KeyDelete(&st_UserKey);
552+
DBModule_MQUser_TimeDelete(&st_DBInfo);
544553
if (pSt_ProtocolHdr->byIsReply || (XENGINE_MQAPP_NETTYPE_HTTP == nNetType))
545554
{
546555
pSt_ProtocolHdr->wReserve = 0;

0 commit comments

Comments
 (0)