How to insert statements that contains apostrophes

2019-02-16 14:28发布

In my iPhone app. I am using an Sqlite database. I have a requirement to store the text in database. The text contains apostrophe s.

For Example:

Insert into tbl_insert values ('It is Steve's Shirt');

How to store this kind of statements in Sqlite database?

What should be done?

Please Help and Suggest.

Thanks.

2条回答
Lonely孤独者°
2楼-- · 2019-02-16 14:56

This is something that I go through in SQL Server and MySQL as well. You should definitely use parameterised SQL queries

See this page for examples in many languages.

I strongly discourage the use of literal strings in the update statement. Use parameterized queries. There's no reason to compromise security

You can write a function which replaces each instance of character ' with ''

http://www.kamath.com/codelibrary/cl003_apostrophe.asp

查看更多
Deceive 欺骗
3楼-- · 2019-02-16 14:56

Simply replace ' characters to ` :)

text = text.replace("'", "`");
查看更多
登录 后发表回答