0

I am new in HTML5 Web SQL Database and I want save a JSON string.

 tx.executeSql("INSERT INTO TA (id, name) VALUES (89,\"{   \"items\":[     {     \"order\": 1,     \"item_id\": 123123,     \"quantity\": 10,     \"price\": 1526896,     \"total\": 15268960   },   {     \"order\": 2,     \"item_id\": 113124,     \"quantity\": 10,     \"price\": 1526896,     \"total\": 15268960   },   {     \"order\": 3,     \"item_id\": 163125,     \"quantity\": 10,     \"price\": 1626896,     \"total\": 16268960   },   {     \"order\": 4,     \"item_id\": 1723165,     \"quantity\": 10,     \"price\": 1726896,     \"total\": 17268960   },   {     \"order\": 5,     \"item_id\": 183190,     \"quantity\": 10,     \"price\": 1826896,     \"total\": 18268960   } ],  \"other\":[           {         \"order\": 1,         \"item\": 123123,         \"price\": 10              },      {         \"order\": 2,         \"item\": 123123,         \"price\": 10              }      ,{         \"order\": 3,         \"item\": 123123,         \"price\": 10      }      ] }\")";

But it not accept quotation marks in value.

I test this sample

tx.executeSql("INSERT INTO TA (id, name) VALUES (90,\"a\")");

Also

tx.executeSql("INSERT INTO TA (id, name) VALUES (90,\"\"a\"\")"); 

And get same result.

4
  • What the error message? Commented Dec 24, 2015 at 18:55
  • Don't put the JSON string directly in the query. Use placeholders and parameters instead: stackoverflow.com/a/23434271/1233508 Commented Dec 24, 2015 at 19:36
  • @Karl Richter HTML5 Web SQL Database never print log or error Commented Dec 24, 2015 at 20:00
  • @DCoder sloved thank you Commented Dec 24, 2015 at 20:01

1 Answer 1

1

Thanks for all answers and specially @DCoder

Don't put the JSON string directly in the query. Use placeholders and parameters instead: stackoverflow.com/a/23434271/1233508

var str  = '{   "items":[     {     "order": 1,     "item_id": 123123,     "quantity": 10,     "price": 1526896,     "total": 15268960   },   {     "order": 2,     "item_id": 113124,     "quantity": 10,     "price": 1526896,     "total": 15268960   },   {     "order": 3,     "item_id": 163125,     "quantity": 10,     "price": 1626896,     "total": 16268960   },   {     "order": 4,     "item_id": 1723165,     "quantity": 10,     "price": 1726896,     "total": 17268960   },   {     "order": 5,     "item_id": 183190,     "quantity": 10,     "price": 1826896,     "total": 18268960   } ],  "other":[           {         "order": 1,         "item": 123123,         "price": 10              },      {         "order": 2,         "item": 123123,         "price": 10              }      ,{         "order": 3,         "item": 123123,         "price": 10      }      ] }';

tx.executeSql('INSERT INTO TA (id, name) VALUES (?,?)',[94,str]);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.