I have a mysql table with a longblob field. I have successfully inserted the blob records into the table and extracted them back into files on disk using python.
Now I want to select the latest version blob from the table and write it to a file on disk using c++ and mysql connector. This is the code I have so far.
It appears to work for smaller blobs, but not enough for large blobs on my database. The max buffer size appears to be near 1000000.
How can I write large longblob files from the mysql select?
string appname = "rocket.exe";
driver = get_driver_instance();
con = driver->connect(mysql_server, mysql_user, mysql_password);
con->setSchema("app");
stmt = con->createStatement();
sqlstring =
"select installer"
" from app_table"
" where appname = '" + appname + "'"
" order by version desc "
" limit 1";
std::istream *blob;
res = stmt->executeQuery(sqlstring);
while (res->next()) {
blob = res->getBlob("installer");
}
char buffer[1000000];
memset(buffer, '\0', 1000000);
blob->read((char*)buffer,1000000);
std::ofstream outfile ("rocket2.exe",std::ofstream::binary);
outfile.write (buffer,1000000);
outfile.close();
delete res; // resultset
delete stmt; // statement
delete con; // connection