mysql blob類型

來源:互聯網
上載者:User

打包 

const std::string CDBObjectManager::GetDetails()
{
 std::string str;
 if(GetElementCount()==0)
 {
  str="";
  return str;
 }
 sg_mgrStringMap.PutInt(str,GetElementCount());  //數量
 sg_mgrStringMap.PutInt(str,GetAttributeCount());//屬性數量
 for(iterator iter = Begin(); iter != End(); ++iter)
 {
  CDBObject* pObject = iter->second;
  if(pObject)
   pObject->BlobCompress(str);
 }
 if(str.size() > 1)
  str.erase(str.size() -1, 1);
 return str;
}

 

int CDBObject::BlobCompress(std::string &strBuf)
{
 int nFieldSize = 0;
 while(1)
 {
  int nAttribute = getAttribute(nFieldSize);
  if(nAttribute < 0)
   break;
  PutInt(strBuf,nAttribute);
  nFieldSize ++;
 }
 return nFieldSize;
}

 

int CPetEgg::getAttribute(int nIndex)
{
 switch(nIndex)
 {
 case 0:
  return GetPetEggID();
  break;
 case 1:
  return GetPetEggType();
  break;
 case 2:
  return GetHatchStartTime();
  break;
 case 3:
  return GetHatchEndTime();
  break;
 default:
  return -1;
 }
}
bool CPetEgg::setAttribute(int nAttribute,int nIndex)
{
  switch(nIndex)
  {
  case 0:
    SetPetEggID(nAttribute);
   break;
  case 1:
    SetPetEggType(nAttribute);
   break;
  case 2:
    SetHatchStartTime(nAttribute);
   break;
  case 3:
    SetHatchEndTime(nAttribute);
   break;
  default:
   return false;
  }
 return true;
}

 

解包

int nQueryResult = pDBReader->query(SQL_QUERY_ROLE_SUPER,pRole->GetID());
 if(nQueryResult != 0)
 {
  return false;
 }
 int nRow = pDBReader->get_result_rows();
 if(nRow != 1)
 {
  return false;
 }
 char *pValue = NULL;
    //取出詳細記錄
 int nLen = pDBReader->get_result(0, db_challenge_details, pValue);
 if (nLen > 0 && pValue != NULL)
 {
  pRole->m_Challenge.LoadCompress(pValue);
 }

 nLen = pDBReader->get_result(0, db_property_details, pValue);
 if (nLen > 0 && pValue != NULL)
 {
  pRole->m_mgrOBPropertyManager.BaseLoadCompress(pValue);
 }

 nLen = pDBReader->get_result(0, db_pet_details, pValue);
 if (nLen > 0 && pValue != NULL)
 {
  pRole->m_mgrPetManager.BaseLoadCompress(pValue);
 }

 

 

bool CDBObjectManager::BaseLoadCompress(char *pValue)
{
 if(NULL == pValue)
  return false;

 std::vector<std::string> vectTmpRecords;  //所有資訊
 std::vector<int> vectAttribute;           //詳細每一個的資訊
 StringSplit(vectTmpRecords,pValue,FIELD_SPLIT);
 int nAttributeCount = 0;
 int nDbAttributeCount = 0;
 int nCount = 0;
 int nSize = vectTmpRecords.size();
 for (int i = 0; i < nSize; i++)
 {
  if (i == 0)
  {
   nCount = String2int(vectTmpRecords[i]);//取出的數量
  }
  else if (i == 1)
  {
   int nAttrCount = String2int(vectTmpRecords[i]);//取出屬性數量
   nDbAttributeCount = nAttrCount;
   int nAllSize = int(nDbAttributeCount*nCount)+2;
   if(nSize != nAllSize)
   {
   // break;
   }
  }
  else
  {
   GetAttribute(vectAttribute, vectTmpRecords[i]);
   nAttributeCount++;
  }
  if (nDbAttributeCount > 0 && nAttributeCount == nDbAttributeCount )
  {
   //break;
   if(vectAttribute.size() <= 0)
   {
    vectAttribute.clear();
    nAttributeCount = 0;
    continue;
   }
   int nID=vectAttribute[0];
   if(nID <= 0)
   {
    vectAttribute.clear();
    nAttributeCount = 0;
    continue;
   }
   /*CDBObject* pObject = new CDBObject(db::CDBObject::SAVE_MODE_NORMAL, nRoleID);
   for (int j = 0; j < vectAttribute.size(); j++)
   {
    pObject->FindFuc(vectAttribute[j], j);
   }
   if (!Insert(nID, pObject))
   {
    delete pObject;
    pObject = NULL;
   }*/
   NewBlobObject(vectAttribute);
   vectAttribute.clear();
   nAttributeCount = 0;
  }
 }
 return true;
}

bool CPetEggManager::NewBlobObject(std::vector<int> &vectAttribute)
{
 if(vectAttribute.size() < 1)
  return false;
 int nID=vectAttribute[0];
 if(nID <= 0)
  return false;
 db::CPetEgg* pPetEgg = new db::CPetEgg(db::CPetEgg::SAVE_MODE_NORMAL, GetRoleID());
 if(pPetEgg == NULL)
  return false;
 for(int j=0;j<vectAttribute.size();j++)
 {
  pPetEgg->setAttribute(vectAttribute[j],j);
 }
 if (!Insert(nID, pPetEgg))
 {
   delete pPetEgg;
   pPetEgg = NULL;
 }
 return true;
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.