Thank you for your expansive reply. Did you run the simple query I asked?
Here's a complete working example
@
// main.cpp
#include <QtCore>
#include <QtSql>
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
QByteArray data;
QFile file("main.cpp");
if (file.open(QIODevice::ReadOnly))
data = file.readAll();
qDebug() << "Original data" << data.size() << "bytes";
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName(":memory:");
if (db.open()) {
QSqlQuery qry(db);
qry.prepare("CREATE TABLE test (id INTEGER PRIMARY KEY, size INTEGER, data BLOB)");
if (!qry.exec())
qWarning() << qry.lastError();
// Insert some blob goodness
qry.prepare("INSERT INTO test (id, size, data) VALUES (?, ?, ?)");
for (int i = 0; i < 5; ++i) {
qry.bindValue(0, i);
qry.bindValue(1, data.size());
qry.bindValue(2, data);
if (!qry.exec())
qWarning() << qry.lastError();
// make the blob grow for some variety
data += data;
}
// Now let us get them back
qry.prepare("SELECT id, size, data FROM test");
if (qry.exec()) {
while (qry.next()) {
qDebug()
<< qry.value(0).toLongLong()
<< qry.value(1).toLongLong() << "stored"
<< qry.value(2).toByteArray().size() << "bytes retrieved";
}
}
else
qWarning() << qry.lastError();
}
return 0;
}
@
If that works (and it will) then the problem is elsewhere in your code.
The size of file you are writing to the database, and the actual size of the byte array of data may never have been the same
The stuff at the end about "receiving bytearray" has nothing to do with your thread title and question. However, incorrectly handling network data is a common way to not have the compete file contents you think you have. The usual mistake is to assume that all the data arrives at the same time.