I am trying to insert the data in JSON format to sqlitedb.
I am able to insert one row into the db. But the second row is not getting inserted.
MESSAGE -> MSG: {"0":"dosage":"150mg","diagnosis":"abc","tm_3":"0","tm_2":"0","tm_1":"1","instructions":"u","medicine_name":"A"}, "1":{"dosage":"250mg","diagnosis":"abc","tm_3":"1","tm_2":"0","tm_1":"0","instructions":"u","medicine_name":"B"}}
I am able to insert the first row but not the second.
Here is the part of the code after table creation :
var totalItems = 7;
var currentArray = [];
var arr = [];
for (var key in e.payload)
{ var prop = e.payload[key];
currentArray.push(prop["medicine_name"]);
currentArray.push(prop["tm_1"]);
currentArray.push(prop["tm_2"]);
currentArray.push(prop["tm_3"]);
currentArray.push(prop["dosage"]);
currentArray.push(prop["diagnosis"]);
currentArray.push(prop["instructions"]);
arr.push(currentArray);
currentArray = [];
};
arr.pop();
$("#app-status-ul").append(arr.length);
for(var idx = 0; idx < arr.length; idx++)
{
var j=arr[idx];
tx.executeSql("INSERT INTO Medicine (medicine_name,tm_1,tm_2,tm_3,dosage,diagnosis,instructions) VALUES ( ?, ?, ?, ?, ?, ?, ?)", j, function(tx, result)
{
$("#app-status-ul").append("Insert succeed");
$("#app-status-ul").append(result);
});
}
The value of arr.length is 1. e.payload is the one i displayed first. I want to insert both the rows. Any idea? I think the problem is with the array but I cant figure it out.
Aucun commentaire:
Enregistrer un commentaire