Teererai Marange
Teererai Marange

Reputation: 2132

javascript: create SQlite statement with escaped double quotes

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?

Upvotes: 1

Views: 1946

Answers (2)

Neil
Neil

Reputation: 55402

Use a parameterised statement:

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

Upvotes: 6

Jeremy J Starcher
Jeremy J Starcher

Reputation: 23863

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

Upvotes: 1

Related Questions