[Qt-interest] QtSql - fail to send blob data

Jason H scorp1us at yahoo.com
Wed Sep 7 19:50:43 CEST 2011


What database, what driver?
I've done blobs before, no problem.



________________________________
From: Cyril <cyril.mailing.list at gmail.com>
To: qt-interest at qt.nokia.com
Sent: Wednesday, September 7, 2011 9:03 AM
Subject: [Qt-interest] QtSql - fail to send blob data


Hi,
I want to insert a record containing a big blob (>10 MB) to mysql. If I do that in a single query, I get an error telling me that a packet is larger than max_allowed_packet (typicaly 1 MB). I don't have the right to increase this setting.
So I had the idea of splitting the data to upload into chunks and doing something like:


QSqlDatabase db;
...

{
  QSqlQuery q1(db);
  q1.prepare("INSERT INTO t (id, data) VALUES(42, '')"); // field data is a LONGBLOB
  q1.exec();
}

QByteArray bigData; // several megabytes of data to insert in DB
const int chunkSize = 50000;

int i = 0;
while(!bigData.isEmpty()) {
  QByteArray chunk = bigData.left(chunkSize);
  bigData = bigData.mid(chunkSize);

  QSqlQuery q2(db);
  q2.prepare("UPDATE t SET data=CONCAT(data, ?) WHERE id=42");
  q2.addBindValue(chunk);
  q2.exec(); //<<<<<< still fails when i==max_allowed_packet/chunkSize

  i++;
}


Does anyone know what is happening? That looks like a bug to me, and really prevents me from doing a basic operation :(

Regards
Cyril
_______________________________________________
Qt-interest mailing list
Qt-interest at qt.nokia.com
http://lists.qt.nokia.com/mailman/listinfo/qt-interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110907/e833d404/attachment.html 


More information about the Qt-interest-old mailing list