PDA

View Full Version : insert binary data into sqlite



sattu
24th March 2011, 14:00
Hi everyone,
I am using qt 4.7.I am trying to store binary data.My binary data is present in QByteArray.
Can any one tell me how to insert ? What is the create and insert statement ?

thanks

high_flyer
24th March 2011, 14:09
http://www.qtcentre.org/threads/39721-Inserting-PNG-into-Database-Escaping-String?highlight=BLOB

stampede
24th March 2011, 14:13
I think you can use BLOB datatype for the data field, so create could look like:

CREATE TABLE test( data BLOB NOT NULL );
and insert QByteArray as any other value, for example:


QByteArray bytes;
...
QSqlQuery query(db);
query.prepare("INSERT INTO test(data) VALUES(:data);");
query.bindValue(":data",bytes);
query.exec();