1
votes

I am trying to escape the double quotation marks in my json string in order to execute the following sqlite statement in phonegap ie. using javascript:

var sqlstatement= 'INSERT INTO ACTIVITY(activity) VALUES("{\"clicks\":100, \"activityTypeCode\":3}")'

However when It try:

tx.executeSql(sqlStatement,errorCB, sucessCB)

the double quotes arent escaped and I go to the errorCallback because of the many pairs of double quotes. is there a way around this?

2
This is a duplicate of "How to escape? data that is being inserted into sqlite database." See following: stackoverflow.com/questions/7608378/… - Kozuch

2 Answers

6
votes

Use a parameterised statement:

tx.executeSql("INSERT INTO ACTIVITY (clicks, activityTypeCode) VALUES (?, ?)",
              [activity.clicks, activity.activityTypeCode], successCB, errorCB);
1
votes

You are trying to store a JSON string it seems, you need a different syntax.

 var insertStatement = "INSERT INTO ACTIVITY (clicks, activityTypeCode) VALUES (100, 3)";

This page might help you with the rest of it:

http://cookbooks.adobe.com/post_Store_data_in_the_HTML5_SQLite_database-19115.html