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

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

發佈了14 篇原創文章 · 獲贊 3 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章