List:MySQL++« Previous MessageNext Message »
From:Jonathan Wakely Date:May 4 2010 10:02am
Subject:Re: Blob Insertion Problem.
View as plain text  
On 4 May 2010 10:49, Kévin Panhalleux wrote:
> First i use this structure to store binary data :
>> typedef struct bitStream
>> {
>>       char * data;
>>       int DataLength;
>> } BitStream;

You know that in C++ the typedef is unnecessary?
You can just say:
struct BitStream { ... };

> and then i finally insert the data using this :
>> query << "INSERT INTO samples VALUES (1,2,3,\"" << mysqlpp::escape;
>> query.write(myStream .data,myStream .DataLength);
>> query << "\")";

istream::write is an unformatted input operation, so the 'escape'
manipulator doesn't get used.

There might be a better way, but I think you need to use
Query::escape_string to create a copy of the data which is escaped,
then write that copy to the stream.

either that, or use formatted input:

query << "INSERT INTO samples VALUES (1,2,3,\"" << mysqlpp::escape
<< std::string(myStream .data,myStream .DataLength)
<< "\")";

As this version uses operator<< it will use the manipulator.
Blob Insertion Problem.K√©vin Panhalleux4 May
  • Re: Blob Insertion Problem.Jonathan Wakely4 May