开发者

How do I stream values from a std::set into MySQL c++ connector setBlob()?

开发者 https://www.devze.com 2023-02-19 19:36 出处:网络
In C++: I have a a std::set of integers In MySQL: I have a table with a blob column I would like to stream the integers into the blob column but I\'m not sure how to do so

In C++: I have a a std::set of integers

In MySQL: I have a table with a blob column

I would like to stream the integers into the blob column but I'm not sure how to do so

edit: Forgot to mention that I need to ensure that the integers are packed as little en开发者_运维百科dian DWORDs


I'm not familar with MySQL library that you're using, but if it's using istream, then it would look like this:

void PutInt(istream &stream, int value)
{
  uint8_t byte[4];

  // converting to little-endian 32bits (DWORD size)
  byte[0] = value; 
  byte[1] = value >> 8;
  byte[2] = value >> 16;
  byte[3] = value >> 24;

  // write to stream
  for (int i = 0 ;i < 4; i++)
    stream>>byte[i];
}

void PutSet(istream &stream, std::set<int> &some_set)
{
  std::set<int>::iterator it;

  for (it = some_set.begin(); it != some_set.end(); it ++)
    PutInt(stream,(*it));
}
0

精彩评论

暂无评论...
验证码 换一张
取 消