List:MySQL++« Previous MessageNext Message »
From:Jonathan Wakely Date:April 28 2010 9:07am
Subject:Re: Insert BLOB from file without extra copy
View as plain text  
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.

std::ifstream in(filename);
Query query = conn.query();
query << "INSERT INTO images (data) VALUES(\"" <<
                mysqlpp::escape << in.rdbuf() << "\")";
Thread
Insert BLOB from file without extra copysinoth28 Apr
  • Re: Insert BLOB from file without extra copyme2228 Apr
    • Re: Insert BLOB from file without extra copysinoth28 Apr
  • Re: Insert BLOB from file without extra copyJonathan Wakely28 Apr
    • Re: Insert BLOB from file without extra copysinoth29 Apr