Blobs getting truncated? 2007-07-06 - By Ron Olson
Back Aloha-
I just started using MySQL++ and while I like it a lot, I'm having a strange problem with saving blobs to the database. Basically, any image over 64k gets truncated; the image goes grey in the query browser, and when I export the image, I get a lot of noise, though the first 64k of it is fine..
I'm using MySQL++ 2.3.0 (just released) with VS2005 on XP and it's talking to a MySQL database: mysql Ver 14.7 Distrib 4.1.20, for redhat-linux-gnu (i686) using readline 4.3
Below is the code I'm using. Might anyone have an idea what I'm doing wrong? I tried following the example off the MySQL++ website, but it didn't seem to work at all (in that it never actually put the record in the table). This code does, but like I said, doesn't seem to send all of it:
#include <mysql++.h> #include <custom.h> #include <transaction.h>
#include <iostream> #include <iomanip> #include <fstream>
using namespace std;
int main(int argc, char* argv[]) { mysqlpp::Connection con(false);
con.connect("mydatabase", "mysqlserver", "binuser", "binuser");
ifstream img_file("c:/temp/winter.jpg", ios::binary | ios::in); if (img_file.is_open()) { try { { std::ostringstream escbuf; escbuf << img_file.rdbuf();
// just a test ... this creates the whole jpg okay string test(escbuf.str()); ofstream outStream("c:/temp/hmm.jpg", std::ios::ate | std::ios::out | std::ios::binary); outStream.write(test.c_str(), test.length()); outStream.flush(); outStream.close();
mysqlpp::Query query = con.query(); query << "INSERT INTO blobtest (id, filename, data) VALUES(6, 'winter.jpg', \"" << mysqlpp::escape << escbuf.str() << "\")";
mysqlpp::ResNSel res = query.execute();
} } catch (const mysqlpp::BadQuery& er) { // Handle any query errors cerr << "Query error: " << er.what() << endl; return -1; } catch (const mysqlpp::BadConversion& er) { // Handle bad conversions cerr << "Conversion error: " << er.what() << endl << "\tretrieved data size: " << er.retrieved << ", actual size: " << er.actual_size << endl; return -1; } catch (const mysqlpp::Exception& er) { // Catch-all for any other MySQL++ exceptions cerr << "Error: " << er.what() << endl; return -1; } }
con.close();
return 0; }
Thanks,
Ron
|
|