I'm trying to insert binary data (QImage
) into a PostgreSQL 8.4.9 bytea
column from Qt 4.8.
My code looks like this:
QImage image;
QByteArray ba;
QBuffer buffer(&ba);
image.save(&buffer, "PNG"); // Save the QImage data into the QBuffer
QSqlQuery query = QSqlQuery(database);
query.prepare("INSERT INTO images (image) "
"VALUES (:image)");
query.bindValue(":image", ba);
query.exec();
qDebug() << query.lastError().text();
This works, but I get the following error:
WARNING: nonstandard use of \ in a string literal LINE 1: ...XECUTE
qpsqlpstmt_1 ('\211PNG... HINT: Use the escape string syntax for
backslashes, e.g., E'\'
How can I escape the data properly to avoid this warning?
EDIT :
Here is some essential information regarding this topic: http://www.postgresql.org/docs/8.4/static/datatype-binary.html
The way I see it, each byte should be surrounded by E''::bytea
before passing to bindValue
. How can I accomplish this?