how to deal with comma and apostrophe chars when inserting into SQLight
i have string that contains apostrophe and comma’s and when i excute insert into SQLight it gives me error for example with string like this :
- ...., 'The Smiths - I Know It's Over', .....
- "Over": syntax error Unable to execute statement
how can i or what can i do to keep the apostrophe’s in the string but preform valid insert? .
im using simple :
5 replies
You are talking about SQLite, aren’t you?
Please have a look at SQLite documentation [sqlite.org]:
A single quote within the string can be encoded by putting two single quotes in a row – as in Pascal.
that means i need to run over each string to check ? isn’t there some build in solution ?
Use QSqlDriver::formatValue [developer.qt.nokia.com] According to Qt documentation it will do the job:
Any embedded single-quote characters are escaped (replaced with two single-quote characters).
Use placeholders and bind them instead of handcrafting things. QSqlQuery docs have the gory details.
You must log in to post a reply. Not a member yet? Register here!




