Mailing List
Home
Forum Home
MySQL General - General MySQL discussion
MySQL++ - Programming with the C++ API to MySQL
MaxDB - Everything about MaxDB, formerly known as SAP DB
ODBC - ODBC with the MySQL Connector/ODBC driver
MySQL on Win32 - Runing MySQL on Windows 9x/Me/NT/2000/XP
Java Help - Mostly related to the MySQL Connector/J driver
Perl - Perl support for MySQL with DBI and DBD::mysql
GUI - MySQL GUI Tools
Announcement
Subjects
mysql openssl Question
ERROR 1045: Access denied for user: 'root@localhost ' (Using
password: NO)
Update one field with more fields from another table
Getting Identity after INSERT
ERROR 2002: Can 't connect to local MySQL server through socket
mysql test 4 1 fails with the gis test
MySQL Cluster Software
Downgrade Mysql from 4 to 3 23
Mysql 4 0 Oracle Stored Procedure Trigger Conversion
Can 't access mysql after kernel upgrade
Executing MySQL Commands From Within C Program
Comparing and writing out BLOBS
Preventing Duplicate Entries
FULLTEXT query format question
Strange behavior, Table Level Permission
Does the binary log enabling affect the MySQL performances?
mysql:it 's a db not a dbms how it 's possible?!
mysql have same function mthod as Oracle decode()
 
Blobs getting truncated?

Blobs getting truncated?

2007-07-06       - By Ron Olson

 Back
Reply:     1     2  

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