完善数据库用户事件
This commit is contained in:
parent
fd5ba3077b
commit
2a8b23135e
|
@ -7,10 +7,12 @@
|
||||||
|
|
||||||
/* 账户在其他地方登录 */
|
/* 账户在其他地方登录 */
|
||||||
#define HGPDTTOOLDB_USEREVENT_CONFLICT 1L
|
#define HGPDTTOOLDB_USEREVENT_CONFLICT 1L
|
||||||
/* 网络连接断开 */
|
/* 网络错误 */
|
||||||
#define HGPDTTOOLDB_USEREVENT_DISCONNECT 2L
|
#define HGPDTTOOLDB_USEREVENT_NETERROR 2L
|
||||||
/* 被管理员账户强制下线 */
|
/* 被管理员账户强制下线 */
|
||||||
#define HGPDTTOOLDB_USEREVENT_REFUSE 3L
|
#define HGPDTTOOLDB_USEREVENT_REFUSE 3L
|
||||||
|
/* 数据库异常 */
|
||||||
|
#define HGPDTTOOLDB_USEREVENT_DBERROR 4L
|
||||||
|
|
||||||
/* 管理员账户 */
|
/* 管理员账户 */
|
||||||
#define HGPDTTOOLDB_USERTYPE_ROOT 1L
|
#define HGPDTTOOLDB_USERTYPE_ROOT 1L
|
||||||
|
|
|
@ -998,18 +998,19 @@ void HGAPI HGPdtToolDbUserMgrImpl::ThreadFunc(HGThread thread, HGPointer param)
|
||||||
{
|
{
|
||||||
HGUInt event = 0;
|
HGUInt event = 0;
|
||||||
|
|
||||||
int connectId;
|
int connectId = -1;
|
||||||
std::string takeUserName;
|
std::string takeUserName;
|
||||||
bool ret = GetUserLoginInfo(p->m_sql, p->m_userName.c_str(), connectId, takeUserName);
|
int ret = GetUserLoginInfo(p->m_sql, p->m_userName.c_str(), connectId, takeUserName);
|
||||||
if (!ret)
|
if (0 != ret)
|
||||||
{
|
{
|
||||||
event = HGPDTTOOLDB_USEREVENT_DISCONNECT;
|
int errNo = mysql_errno(p->m_sql);
|
||||||
|
event = (errNo >= 1158 && errNo <= 1161) ? HGPDTTOOLDB_USEREVENT_NETERROR : HGPDTTOOLDB_USEREVENT_DBERROR;
|
||||||
}
|
}
|
||||||
else if (takeUserName == "root" && p->m_userName != takeUserName)
|
else if (takeUserName == "root" && takeUserName != p->m_userName)
|
||||||
{
|
{
|
||||||
event = HGPDTTOOLDB_USEREVENT_REFUSE;
|
event = HGPDTTOOLDB_USEREVENT_REFUSE;
|
||||||
}
|
}
|
||||||
else if (connectId != p->m_connectId)
|
else if (connectId != -1 && connectId != p->m_connectId)
|
||||||
{
|
{
|
||||||
event = HGPDTTOOLDB_USEREVENT_CONFLICT;
|
event = HGPDTTOOLDB_USEREVENT_CONFLICT;
|
||||||
}
|
}
|
||||||
|
@ -1142,7 +1143,7 @@ bool HGPdtToolDbUserMgrImpl::SetUserLoginInfo(MYSQL* sql, const HGChar* userName
|
||||||
return (0 == ret) ? true : false;
|
return (0 == ret) ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HGPdtToolDbUserMgrImpl::GetUserLoginInfo(MYSQL* sql, const HGChar* userName, int& connectId, std::string& takeUserName)
|
int HGPdtToolDbUserMgrImpl::GetUserLoginInfo(MYSQL* sql, const HGChar* userName, int& connectId, std::string& takeUserName)
|
||||||
{
|
{
|
||||||
assert(NULL != sql);
|
assert(NULL != sql);
|
||||||
assert(NULL != userName && 0 != *userName);
|
assert(NULL != userName && 0 != *userName);
|
||||||
|
@ -1154,7 +1155,7 @@ bool HGPdtToolDbUserMgrImpl::GetUserLoginInfo(MYSQL* sql, const HGChar* userName
|
||||||
int ret = mysql_query(sql, sqlCmd);
|
int ret = mysql_query(sql, sqlCmd);
|
||||||
if (0 != ret)
|
if (0 != ret)
|
||||||
{
|
{
|
||||||
return false;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
MYSQL_RES* sqlRes = mysql_use_result(sql);
|
MYSQL_RES* sqlRes = mysql_use_result(sql);
|
||||||
|
@ -1171,7 +1172,7 @@ bool HGPdtToolDbUserMgrImpl::GetUserLoginInfo(MYSQL* sql, const HGChar* userName
|
||||||
mysql_free_result(sqlRes);
|
mysql_free_result(sqlRes);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int HGPdtToolDbUserMgrImpl::CreateFileTable(MYSQL* sql)
|
int HGPdtToolDbUserMgrImpl::CreateFileTable(MYSQL* sql)
|
||||||
|
|
|
@ -46,7 +46,7 @@ private:
|
||||||
static std::string GetAuthString(MYSQL* sql, const HGChar* pwd);
|
static std::string GetAuthString(MYSQL* sql, const HGChar* pwd);
|
||||||
static int GetConnectId(MYSQL* sql);
|
static int GetConnectId(MYSQL* sql);
|
||||||
static bool SetUserLoginInfo(MYSQL* sql, const HGChar* userName, int connectId, const std::string& takeUserName);
|
static bool SetUserLoginInfo(MYSQL* sql, const HGChar* userName, int connectId, const std::string& takeUserName);
|
||||||
static bool GetUserLoginInfo(MYSQL* sql, const HGChar* userName, int &connectId, std::string &takeUserName);
|
static int GetUserLoginInfo(MYSQL* sql, const HGChar* userName, int &connectId, std::string &takeUserName);
|
||||||
|
|
||||||
int CreateFileTable(MYSQL* sql);
|
int CreateFileTable(MYSQL* sql);
|
||||||
int CreateMainTestTable(MYSQL *sql);
|
int CreateMainTestTable(MYSQL *sql);
|
||||||
|
|
Loading…
Reference in New Issue