在mysql connector / c ++中使用setblob设置二进制数据会导致崩溃

时间:2009-07-13 18:10:24

标签: c++ mysql binary-data

我尝试使用setBlob(),如下所示:


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


char b[20];
DataBuf buffer((char*)b, 20);
istream stream(&buffer);

PreparedStatement* s = con->PrepareStatement("insert into mytable (mybin) values (?)");
s->setBlob(1, &stream);
int rows = s->executeUpdate();

这在executeUpdate()崩溃了。我做错了什么?

1 个答案:

答案 0 :(得分:1)

你确定它没有崩溃:

s->setBlob(1, &stream);

检查调试器以确保s不是NULL或废话值。