Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert statements that contains apostrophes into Sqlite database

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

For example:

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

How to store this kind of statements in Sqlite database?

like image 557
Parth Bhatt Avatar asked Nov 30 '10 04:11

Parth Bhatt


People also ask

How do I insert an apostrophe in SQL database?

The short answer is to use two single quotes - '' - in order for an SQL database to store the value as ' .

Which method is used for insert records into SQLite database?

To insert data into a table, you use the INSERT statement. SQLite provides various forms of the INSERT statements that allow you to insert a single row, multiple rows, and default values into a table. In addition, you can insert a row into a table using data provided by a SELECT statement.


1 Answers

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

like image 138
Ranhiru Jude Cooray Avatar answered Sep 28 '22 18:09

Ranhiru Jude Cooray