On 28 April 2010 03:07, sinoth wrote:
> This may be more of a C++ question but hopefully one of you has run across
> it. As per the tutorial "Dealing with Binary Data", the correct way to load
> a file and insert it as a BLOB seems to be to read it to a char* array, then
> use std::string's assign function to copy the data. From there you can
> shove the string into the query using stream operators. It bugs me that the
> data has to be copied and exist in memory twice.
> Is there any other way to insert BLOB data from a file without having to
> copy it to a std::string? I looked at std::stringstream, but even it's
> str() function returns a copy of the data, which I'm trying to avoid.
Query query = conn.query();
query << "INSERT INTO images (data) VALUES(\"" <<
mysqlpp::escape << in.rdbuf() << "\")";