PDA

View Full Version : [QT5.4] QtSQL MySql driver fails to write a string with ' to table



LaurentDuroisin
21st December 2015, 13:06
Hi!

I'm trying to write a string with ' to a table but QSqlQuery returns a syntax error near animateur :



if (!query.exec("INSERT INTO TEST_DESCRIPTIONS (DESCRIPTION, USER_ID) VALUES('L\'animateur ...',"+QString(id)+");")) {
QSqlError error = query.lastError();
QMessageBox::critical(nullptr, "Write Error", "Failed to save information to database"+error.text());
}


With MySQL client command line, it insert the row into the table without any problem.

LaurentDuroisin
21st December 2015, 15:47
I've found why, the compiler escape the character ' so I had to make a double escapment.

\\'