QSqlDatabase and Postgres - Insert bytes into database
I have a Postgres database with a BYTEA field.
I want to insert bytes into this fields.
I'm currently doing this:
Code:
QString query
= "INSERT INTO images (id, bytes) VALUES (1, :data)";
sql.bindValue(":data", data);
sql.exec();
This failes and I get the following error:
Code:
ERROR: syntax error at or near "("
LINE 1: EXECUTE ('\\000\\000\\000\\000\\000\\000\\000\\000\\000\\00...
If I replace the :data with NULL, everything works fine.
Does anyone know how to insert binary dat into Postgres using QSqlDatabase and QSqlQuery.
Any reference to an online tutorial will also be greate, because I can't find one.
Thank you
Re: QSqlDatabase and Postgres - Insert bytes into database
When I remember right it's a "problem" of the driver. You have to convert it to base64 before inserting:
Code:
sql.bindValue(":data", data.toBase64());