androidsqldatabasesqlitedouble-quotes

How to insert double quote ( " ) into SQLite Database Varchar field?


I'm trying to insert into a table with this field TITLE varchar(200) NOT NULL the next sentence:

INSERT OR IGNORE INTO EXAMPLETABLE VALUES ("1-Preludi \"Obrint Pas 2011\"", ... 

The problem is that SQLite missunderstand the \" escape caracter , and i don't know how to put it to resolve the problem (Maybe a character code?) in my Android program.


Solution

  • To insert values into a database you should always use SQLiteStatement (HowTo) as they escape your values and prevent your app from being targeted with SQL-Injections.

    Also, if you're inserting multiple values (say in a loop), executing a precompiled statement with different bound values is much faster than a normal insert-statement.