Search code examples
javascriptandroidsqlitetitanium

Difficulty in escaping single quote character while SQLite database insertion


I have to insert certain text in database which may contain characters with single quotes and double quotes.

For eg: "Lumix" or something like Vijay's

I have successfully escaped the double quotes like this:

if(fdata.search('"') != -1) {


fdata = fdata.replace(/(['"])/g, "\\$1");



}  

But I am not understanding how to escape the single quotes. Without escaping the single quotes SQLite is not accepting the data. How to solve the issue? Thanks in advance!


Solution

  • Use parameters, then you don't need to escape anything:

    db.execute('INSERT INTO MyTable(ID, Name) VALUES(?, ?)', 123, name);