您的位置:首页 > 编程语言 > C语言/C++

How do I use MySQL C++ Connector for storing binary data?

2009-07-27 15:28 555 查看
http://stackoverflow.com/questions/1071120/how-do-i-use-mysql-c-connector-for-storing-binary-data

You have to subclass streambuf e.g. like this:

class DataBuf : public streambuf
{
public:
   DataBuf(char * d, size_t s) {
      setg(d, d, d + s);
   }
};

Then you can instantiate an istream object which uses a DataBuf as buffer, which itself uses your block of binary data. Supposing that binarySize specifies the size of your binary data in bytes (sizeof(char) should be one byte), you could do this like so:

DataBuf buffer((char*)address, binarySize);
istream stream(&buffer);

That istream object you can now pass to setBlob().

Regards, Elrohir
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: