群组服务器,数据库写 持续扩展ing...
[函数接口定义]
/* CLASS_BEGIN *****************************************************
类名: CImGroupDbWrite
功能: IM群组服务器数据库写对象
版本: V1.0
时间: 2012-2-27 创建
实现: Snight Q:51171107
CLASS_END ******************************************************/
#ifndef H_CIMGROUPDBWRITE_H
#define H_CIMGROUPDBWRITE_H
#include "MysqlHelper.h"
#include "HashMap.h"
class CImGroupDbWrite : public CMysqlDataBase
{
public:
CImGroupDbWrite(void);
~CImGroupDbWrite(void);
public:
/*
增加或更新群组基本属性
@ ai64GroupId 群组ID
@ ai64CreaterID 创建者ID
@ abyType 群组状态
return: -1 程序错误; 0 正常; 其他数据库操作错误
*/
int AddOrUpdateGroupBSProperty( SInt64 ai64GroupId,
SInt64 ai64CreaterID,
SInt8 abyType,
UInt64& ai64AffectRows);
/*
增加或更新群组动态属性
@ ai64GroupId 群ID
@ ai64OwnerID 群所有者
@ alLevel 群等级
@ alParentsType 父类型
@ alChildType 子类型
@ apName 群名称
@ apAnnouncement 群公告
@ apDescription 群描述
@ ai8JoinType 申请加入类型
return: -1 程序错误; 0 正常; 其他数据库操作错误
*/
int AddOrUpdateGroupDYProperty( SInt64 ai64GroupId, SInt64 ai64OwnerID, SLong alLevel,
SLong alParentsType, SLong alChildType, const char* apName,
const char* apAnnouncement, const char* apDescription,SInt8 ai8JoinType, UInt64& ai64AffectRows);
/*
执行Sql 语句
@ aiStatement Sql 语句
*/
int SqlExecuted(std::string& aiStatement, UInt64& ai64AffectRows);
};
#endif//H_CIMGROUPDBWRITE_H
【实现文件】
#include "SImGroupDbWrite.h"
#include "CRunningLog.h"
CImGroupDbWrite::CImGroupDbWrite(void)
{
}
CImGroupDbWrite::~CImGroupDbWrite(void)
{
}
/*
增加或更新群组基本属性
@ ai64GroupId 群组ID
@ ai64CreaterID 创建者ID
@ abyType 群组状态
return: -1 程序错误; 0 正常; 其他数据库操作错误
*/
int CImGroupDbWrite::AddOrUpdateGroupBSProperty(SInt64 ai64GroupId, SInt64 ai64CreaterID, SInt8 abyType, UInt64& ai64AffectRows)
{
CMysqStmt* lpStmt = StmtInit();
int liRet = -1;
if (lpStmt)
{
if (0 == (liRet = lpStmt->StmtPrepare( " call pr_group_base_property_add_or_update (%I64d, %I64d, %d)",ai64GroupId, ai64CreaterID, abyType)))
{
liRet = lpStmt->StmtExcute(); // 执行语句
ai64AffectRows = lpStmt->StmtAffectedRows(); // 检查背影响的行数
}
else
{
ERROR_LOG("ERROR: StmtPrepare() pr_group_base_property_add_or_update 失败:%d", liRet);
}
lpStmt->StmtUnInit();
}
if(MySql_SvrGoneAway == liRet)
{
ERROR_LOG("ERROR: CImGroupDbRead::AddOrUpdateGroupBSProperty pr_group_base_property_add_or_update ret = %d; 重新连接数据库", ReConnect());
}
return liRet;
}
int CImGroupDbWrite::AddOrUpdateGroupDYProperty( SInt64 ai64GroupId, SInt64 ai64OwnerID, SLong alLevel,
SLong alParentsType,SLong alChildType,const char* apName,
const char* apAnnouncement,const char* apDescription,SInt8 ai8JoinType, UInt64& ai64AffectRows)
{
CMysqStmt* lpStmt = StmtInit();
int liRet = -1;
if (lpStmt)
{
if (0 == (liRet = lpStmt->StmtPrepare( " call pr_group_dynamic_property_add_or_update (%I64d, %I64d, %d, %d, %d, '%s', '%s', '%s', %d)",
ai64GroupId, ai64OwnerID, alLevel,alParentsType, alChildType, apName, apAnnouncement, apDescription, ai8JoinType)))
{
liRet = lpStmt->StmtExcute(); // 执行语句
ai64AffectRows = lpStmt->StmtAffectedRows(); // 检查背影响的行数
}
else
{
ERROR_LOG("ERROR: StmtPrepare() pr_group_dynamic_property_add_or_update 失败:%d", liRet);
}
lpStmt->StmtUnInit();
}
if(MySql_SvrGoneAway == liRet)
{
ERROR_LOG("ERROR: CImGroupDbRead::AddOrUpdateGroupDYProperty pr_group_dynamic_property_add_or_update ret = %d; 重新连接数据库", ReConnect());
}
return liRet;
}
int CImGroupDbWrite::SqlExecuted(std::string& aiStatement, UInt64& ai64AffectRows)
{
CMysqStmt* lpStmt = StmtInit();
int liRet = -1;
if (lpStmt)
{
if (0 == (liRet = lpStmt->StmtPrepareLarge((char*)aiStatement.c_str())))
{
liRet = lpStmt->StmtExcute(); // 执行语句
const char* lpRet = lpStmt->StmtError();
ai64AffectRows = lpStmt->StmtAffectedRows(); // 检查背影响的行数
}
else
{
ERROR_LOG("ERROR: StmtPrepare() 失败:%d 原因:%s", liRet, lpStmt->StmtError());
}
lpStmt->StmtUnInit();
}
if(MySql_SvrGoneAway == liRet)
{
ERROR_LOG("ERROR: CImGroupDbRead::AddOrUpdateGroupDYProperty pr_group_dynamic_property_add_or_update ret = %d; 重新连接数据库", ReConnect());
}
return liRet;
}