Show the code where you save and read from db. This works ok:
#include <QApplication>
#include <QtCore>
#include <QtSql>
int main(int argc, char *argv[])
{
bytes.resize(6);
bytes[0] = 79;
bytes[1] = 28;
bytes[2] = 41;
bytes[3] = 00;
bytes[4] = 27;
bytes[5] = 11;
qDebug() << "bytes size: " << bytes.size();
db.setDatabaseName("testdb");
db.open();
query.exec("DROP TABLE test;");
query.exec("CREATE TABLE test( data BLOB );");
query.prepare("INSERT INTO test VALUES(:data);");
query.bindValue(":data",bytes);
query.exec();
query.exec("SELECT data FROM test;");
if( query.next() ){
qDebug() << "from db size: " << data.size();
qDebug() << "equal?" << (data==bytes);
}
return 0;
}
#include <QApplication>
#include <QtCore>
#include <QtSql>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QByteArray bytes;
bytes.resize(6);
bytes[0] = 79;
bytes[1] = 28;
bytes[2] = 41;
bytes[3] = 00;
bytes[4] = 27;
bytes[5] = 11;
qDebug() << "bytes size: " << bytes.size();
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("testdb");
db.open();
QSqlQuery query(db);
query.exec("DROP TABLE test;");
query.exec("CREATE TABLE test( data BLOB );");
query.prepare("INSERT INTO test VALUES(:data);");
query.bindValue(":data",bytes);
query.exec();
query.exec("SELECT data FROM test;");
if( query.next() ){
QByteArray data = query.value(0).toByteArray();
qDebug() << "from db size: " << data.size();
qDebug() << "equal?" << (data==bytes);
}
return 0;
}
To copy to clipboard, switch view to plain text mode
Output:
bytes size: 6
from db size: 6
equal? true
Bookmarks