A
A
al_indigo2013-09-29 16:08:40
SQL
al_indigo, 2013-09-29 16:08:40

Escaping characters in QT?

I am writing a program that works with sqlite on QT 5.1. I just discovered with surprise that contrary to the documentation, there is no character escaping at all when preparing queries. That is, if you accidentally put a comma, quotes in the text, or even substitute SQL code, QT does not follow this in any way.
Sample code to illustrate:

QSqlQuery injectTest(db);
QString test("asdasd, asd,' , ");
injectTest.prepare("UPDATE testtable SET text = :text WHERE id = 0");
injectTest.bindValue(":text", QVariant(test));
injectTest.exec();

At the same time, the following query is trying to be executed (and of course, it cannot pass): The QT documentation says the following: “Besides performance, one advantage of placeholders is that you can easily specify arbitrary values ​​without having to worry about escaping special characters.” What can be wrong? Am I screwing up somewhere, or is this some incredible bug in QT?
UPDATE testtable SET text = asdasd, asd,' ,

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
al_indigo, 2013-09-29
@al_indigo

m08pvv: it doesn't escape escape sequences either, I checked. So hardly.
They suspect that I am doing something wrong, because I could not google anything on this topic

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question