Set binary data using setblob in mysql connector/c

2019-08-10 01:04发布

问题:

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:

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.