//存Buffer
bool CRsDupRgn::SaveBufferField(CBaseDBEntity *pGoods, const char* szFiledName, _RecordsetPtr &rs)
{
	if(pGoods == NULL)	return false;
	if(szFiledName == NULL) return false;

	VARIANT varBLOB;
	SAFEARRAY* psa;

	CEntityProperty* ep = pGoods->GetDataEntityManager().GetEntityProperty(string(szFiledName));
	if(NULL == ep) return false;

	BYTE* buffer = NULL;
	long dataSize = ep->GetBufSize(0);
	if(dataSize)
	{
		buffer = new BYTE[dataSize];
		ep->GetBufAttr(0, (void*)buffer, dataSize);
		
		long lSize=(long)dataSize;
		SAFEARRAYBOUND rgsabound[1];
		rgsabound[0].lLbound=0;
		rgsabound[0].cElements=lSize;
		psa=SafeArrayCreate(VT_UI1,1,rgsabound);

		for(long i=0;i<lSize;i++)
		{
			SafeArrayPutElement(psa,&i,&buffer[i]);
		}
		varBLOB.vt=VT_ARRAY|VT_UI1;
		varBLOB.parray=psa;

		try
		{
			rs->GetFields()->GetItem(szFiledName)->AppendChunk(varBLOB);
		}
		catch(_com_error e)
		{
			PrintErr(CStringReading::LoadString(IDS_DBS_RSDUPRGN, STR_DBS_DUPRGN_SAVERGNOBJFAIL), e);
			SAFE_DELETE_ARRAY(buffer);
			return false;
		}
		SafeArrayDestroy(psa);
	}
	SAFE_DELETE_ARRAY(buffer);
	return true;
}
Beispiel #2
0
void CDBPlayer::AddEntityDataToMsg(DB_OPERATION_TYPE opType, vector<BYTE>& pBA)
{
    // 传递来的消息前面已经加入了
    // OPEntityID:    4byte, 操作实体的ID值
    // DBOP Type:     1byte, 数据库操作类型(枚举值)
    // MSG ID:        4byte, 该消息的MSGID
    // Entity Num:    2byte, 该实体个数
    WORD attrNum = m_mapDirtyAttrData.size();
    _AddToByteArray(&pBA, m_GUID); // 实体ID
    _AddToByteArray(&pBA, (WORD)attrNum); // 属性种类个数

    //--新格式
    //变量名字符串长度(long)
    //变量名字符串
    //变量类型(long)
    //变量数据长度(long)
    //变量数据
    set<string>::iterator itr = m_mapDirtyAttrData.begin();
    for(; itr != m_mapDirtyAttrData.end(); itr++)
    {
        CEntityProperty* ep = GetDataEntityManager().GetEntityProperty(*itr);
        if(ep)
        {
            _AddToByteArray(&pBA, (long)(*itr).size());//变量名字符串长度(long)
            _AddToByteArray(&pBA, (*itr).c_str());//变量名字符串
            _AddToByteArray(&pBA, (long)ep->GetDataType());//变量类型(long)
            _AddToByteArray(&pBA, (long)ep->GetBufSize(0));//变量数据长度(long)
            switch(ep->GetDataType())
            {
            case DATA_OBJECT_TIME:
            {
                // 6个long值 : 年 月 日 时 分 秒
                BYTE timeValue[6*sizeof(DWORD)];
                memset(timeValue, 0, 6*sizeof(DWORD));
                ep->GetBufAttr(0, (void*)timeValue, 6*sizeof(DWORD));
                _AddToByteArray(&pBA, timeValue, 6*sizeof(DWORD));
            }
            break;
            case DATA_OBJECT_STRING:
            {
                _AddToByteArray(&pBA, ep->GetStringAttr(0));//变量数据
            }
            break;
            case DATA_OBJECT_FLOAT:
            case DATA_OBJECT_LONG:
            case DATA_OBJECT_SHORT:
            case DATA_OBJECT_ULONG:
            case DATA_OBJECT_USHORT:
            case DATA_OBJECT_BOOL:
            case DATA_OBJECT_CHAR:
            case DATA_OBJECT_BYTE:
            case DATA_OBJECT_WORD:
            case DATA_OBJECT_DWORD:
            {
                _AddToByteArray(&pBA, (long)ep->GetLongAttr(0));//变量数据
            }
            break;
            case DATA_OBJECT_GUID:
            {
                CGUID tGUID;
                ep->GetGuidAttr(0, tGUID);
                _AddToByteArray(&pBA, tGUID);//变量数据
            }
            break;
            case DATA_OBJECT_BUFFER:
            {
                long bufSize = ep->GetBufSize(0);
                if(bufSize)
                {
                    BYTE* buf = new BYTE[bufSize];
                    ep->GetBufAttr(0, (void*)buf, bufSize);
                    _AddToByteArray(&pBA, buf, bufSize);//变量数据
                    SAFE_DELETE_ARRAY(buf);
                }
            }
            break;
            }
        }
    }
    m_mapDirtyAttrData.clear();
}