1

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?

Teererai Marange
  • 2,044
  • 4
  • 32
  • 50
  • This is a duplicate of "How to escape? data that is being inserted into sqlite database." See following: http://stackoverflow.com/questions/7608378/how-to-escape-data-that-is-being-inserted-into-sqlite-database – Kozuch Nov 08 '14 at 11:37

2 Answers2

6

Use a parameterised statement:

tx.executeSql("INSERT INTO ACTIVITY (clicks, activityTypeCode) VALUES (?, ?)",
              [activity.clicks, activity.activityTypeCode], successCB, errorCB);
Neil
  • 54,642
  • 8
  • 60
  • 72
1

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

Jeremy J Starcher
  • 23,369
  • 6
  • 54
  • 74