[Qt-interest] QtSql - fail to send blob data
Cyril
cyril.mailing.list at gmail.com
Wed Sep 7 15:03:45 CEST 2011
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110907/68cc6f25/attachment.html
More information about the Qt-interest-old
mailing list