QPSQL: Unable to create query, image bytea
Solved
General and Desktop
-
I am trying trying to insert images into tables but I get this error:
"INSERT INTO Registrations.Customer_Picutre (name, image) VALUES (?, ?)"
QSqlError("42601", "QPSQL: Unable to create query", "ERROR: syntax error at or near "("\nLINE 1: EXECUTE ('asdf', '\xffd8ffe000104a4649460001010100600060000...\n ^\n(42601)")
"/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDLany idea in what's wrong in my code?
query.exec("CREATE EXTENSION citext;"); query.exec("CREATE SCHEMA Registrations;"); query.exec("create table Registrations.Customer_Picture" "(colname SERIAL primary key, " "name CITEXT, " "image bytea)"); QString folder = QCoreApplication::applicationDirPath() + "/images"; QString img = folder + "/new.jpg"; QFile* file = new QFile(img); file->open(QIODevice::ReadOnly); QByteArray image = file->readAll(); QString encoded = QString(image.toBase64()); //insert picture query.prepare("INSERT INTO Registrations.Customer_Picutre (name, image) " "VALUES (:name, :image)"); query.bindValue(":name", ui->name_lineEdit_mainData->text()); query.bindValue(":image", encoded, QSql::In | QSql::Binary); query.exec();
-
Your query syntax is wrong. Please check it. Many sql query syntax checkers in google. Copy paste ur query and check it before placing in code. You can also check ur query sql command prompt of ur da.