Results 1 to 1 of 1

Thread: QSqlQuery Insert BLOB, But Not all the BLOB Is Inserted?

  1. #1
    Join Date
    Jan 2013
    Posts
    11
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSqlQuery Insert BLOB, But Not all the BLOB Is Inserted?

    Hello,

    I am inserting Image Data from a QNetworkReply into a MySQL Table.
    It inserts most records fine, but some have corrupted BLOB data. I am inserting images from a QNetworkReply.

    When i check the images in the Database, i find some are corrupted, and the bottom parts of the image seem to having missing/corrupt data, so it looks like part of the image was corrupted, or it didn't finish inserting the BLOB data in the query.

    I can confirm all the data is received via the QNetworkReply because i create QLabels and Insert the Data into a QPixmap to view what it had downloaded before it inserts the data into the database.
    I should mention, this QNetworkReply *reply, is received from the QNetworkAccessManager SIGNAL finished(QNetworkReply*).

    Qt Code:
    1. QByteArray imageData = reply->readAll();
    2. QLabel *label = new QLabel();
    3. QPixmap pixmap;
    4. pixmap.loadFromData(imageData);
    5. label->setPixmap(pixmap);
    6. label->show();
    To copy to clipboard, switch view to plain text mode 

    Then i insert the data to the database

    Qt Code:
    1. QSqlQuery query(db);
    2. query.prepare("INSERT INTO altimages (productId, data) VALUES (:productId, :data);");
    3. query.bindValue(":productId", productId);
    4. query.bindValue(":data", imageData);
    5. if (!query.exec()){
    6. qDebug() << "Error Inserting Data: " << query.lastError() << endl;
    7. }
    To copy to clipboard, switch view to plain text mode 

    The last image inserted is corrupted, and also some other inserts in the middle of the insert queue, so i think that the query is terminated or destroyed and the QSqlQuery is not completely executed?

    Here is the resulting image: Untitled-1.jpg

    Am i missing something ? Is the query not finishing properly?

    Thank you.


    Edit: I just checked also if the Bound Values of the Query were correct by creating QLabels and QPixmaps and seeing what the data was executed, and everytime, the pictures are ok and not corrupted.

    Qt Code:
    1. QLabel *label = new QLabel();
    2. QPixmap pixmap;
    3. pixmap.loadFromData(query.boundValue(":data").toByteArray());
    4. label->setPixmap(pixmap);
    5. label->show();
    To copy to clipboard, switch view to plain text mode 

    I wonder why still in the database I'm seeing the Values of the BLOB with Corrupted or what looks more like incomplete blob data images. I'm using MYSQL Workbench to view the file in the database.

    Edit: Just found this on Stack OverFlow, and wondering if this is the reason.


    Added after 16 minutes:


    Sorry... this is kinda silly, but i thought BLOB was alot larger than 64kb...

    BLOBs are restricted to 64KB, MEDIUMBLOBS to 16MB and LARGEBLOBS to 2GB

    Changing that fixed it all.. Hope this helps someone save a few hours :-( /facepalm!
    Last edited by zerokewl; 10th September 2013 at 08:01.

Similar Threads

  1. Insert a BLOB to ORACLE
    By Qiieha in forum General Programming
    Replies: 0
    Last Post: 5th April 2011, 15:23
  2. How to insert BLOB into MySQL with Qt?
    By babygal in forum Qt Programming
    Replies: 3
    Last Post: 26th August 2010, 12:26
  3. Replies: 2
    Last Post: 17th February 2010, 14:32
  4. QODBC on BLOB
    By baray98 in forum Qt Programming
    Replies: 0
    Last Post: 6th November 2009, 23:26
  5. Save PDF to BLOB
    By wirasto in forum Qt Programming
    Replies: 1
    Last Post: 24th May 2009, 06:47

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.