Set binary data using setblob in mysql connector/c

2019-08-10 01:12发布

I tried to use setBlob() as follows:


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();

This crashes at executeUpdate(). What am I doing wrong?

1条回答
劫难
2楼-- · 2019-08-10 01:58

Are you sure that it isn't crashing on:

s->setBlob(1, &stream);

Check the debugger to make sure that s isn't NULL, or a crap value.

查看更多
登录 后发表回答