Results 1 to 2 of 2

Thread: problem: inserting a BLOB into sqlite3 with QT4.3

  1. #1
    Join Date
    Sep 2007
    Posts
    31
    Thanked 1 Time in 1 Post

    Angry problem: inserting a BLOB into sqlite3 with QT4.3

    Hi,

    I can't succeed in inserting a BLOG field into a sqlite 3 database with qsqlQuery (I use QT 4.3)
    Here is the source code I use:

    QByteArray *bytes1 = new QByteArray();
    QBuffer pixBigBuf(bytes1);
    pixBigBuf.open(QIODevice::WriteOnly);
    pixBig.save(&pixBigBuf, "JPG");
    Logger::log(Logger::errorLevel, QString("= = = =>") + QVariant(bytes1->size()).toString());

    query.prepare("insert into media(filename,type,view, dataBig) values (:filename, :type, :view, :dataBig)");
    query.bindValue(":filename",filename);
    query.bindValue(":type",0);
    query.bindValue(":view","none");
    //bytes1.const
    query.bindValue(":dataBig", bytes1->constData());
    query.exec();

    The size of the bytearray to insert is ok (11000) but after the insertion, the field takes only 4 bytes in the database...

    However, If I use the sqlite command line tool, I succeed in inserting several bytes into the blob field.

    I saw that some people succeeded by converting qbytearray into a qstring and replacing NULL and ' caracters by special ones to avoid insertion problem. Is it the way?

    Best Regards,
    Oscar

  2. #2
    Join Date
    Sep 2007
    Posts
    31
    Thanked 1 Time in 1 Post

    Smile Re: problem: inserting a BLOB into sqlite3 with QT4.3

    Well, my problem was elsewhere.
    My error was to believe the command line tool sqlite when it displays only the first 4 bytes of the blob field.
    It was only due to the fact that the fifth caracter was a carriage return...

    Add to this a little bug elsewhere in the display of the blob and you stay on the problem for a long time!

    All the best,
    Oscar

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.