PDA

View Full Version : problem: inserting a BLOB into sqlite3 with QT4.3



oscar
18th November 2007, 11:38
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

oscar
18th November 2007, 13:38
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