IM 开源项目 群组服务 数据库设计-数据库访问 (04)

群组服务器,数据库写 持续扩展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;

}


 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值