The question for reading from a blob field is answered here:
To write to a blob field, it is something like this:
string strByteStream = "...";
mysqlpp::Query useQuery = conn.query();
useQuery << "INSERT INTO "
<< "tablename(ByteStream) "
<< "VALUES(CONVERT('" << strByteStream << "' USING binary)" <<
Where strByteStream needs to be an escaped string. You can escape it
yourself, or you can use the MySql C API function, "mysql_escape_string".
The characters that need escaping are (expressions typed in C++ syntax):
0x00 can be escaped with "\\0"
0x1A can be escaped with "\\Z"
'\n' can be escaped with "\\n"
'\r' can be escaped with "\\r"
'\\' can be escaped with "\\\\"
'\'' can be escaped with "\\'"
'\"' can be escaped with "\\\"";
- Bill Krahmer
Ankur G35 Saxena wrote:
> Hi, I wanted to read and write a C++ structure to the DB. I went
> through the example given and from this sinppet of code I got from the
> user mannual, had a small Q.
> I thought that std::string is a /0 delimited string, if so, how does
> this work? If the binary data has a /0 inbetween somwhere in there,
> wouldnt the string fill be shortened when pushed into the strbuf?
> ostringstream strbuf;
> char *read_buffer = new char[blen];
> In.read(read_buffer, blen);
> string fill(read_buffer, blen);
> strbuf << "INSERT INTO " << MY_TABLE << " (" << MY_FIELD
> << ")
> VALUES(\"" << mysqlpp::escape << fill << "\")" << ends;