Pantek Library
Hosting Provided By
CybrHost
High Speed Hosting

Blobs getting truncated?

From: Ron Olson <tachoknight(at)gmail.com>
Date: Fri Jul 06 2007 - 10:09:36 EDT


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[])
{

Do you need help?X

    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 Received on Fri Jul 6 10:09:57 2007

This archive was generated by hypermail 2.1.8 : Fri Jul 06 2007 - 21:25:57 EDT

Do you need more help?X

Contact Us  Legal Notices  Order Services Online 
Pantek Home  Privacy Policy  IT news  Site Map  Pantek Library