Afterwards, use a $http call in the controller which would update sqlite database every time the controller is called. Here goes an example to make a $http request call,
I would suggest storing whole JSON string into a single table column and converting it into a object whenever required. It will also reduce number of lines of code.
You can convert JSON string into object by using angular.fromJson(JSONString).
We should not use “$scope.debtdata = angular.fromJson($scope.debtrow);” before inserting data into the database. It will convert debtdata into [object] [object].
Instead of it store “data” directly into the database which will be in a form of string.
While retrieving it back from the database, i.e whenever we want to utilize the data in our app which will be in a form of a string. We can use angular.fromJson() and convert it to an object to use them.
var deburl='http://tmcs.no-ip.info:82/iAutoCount/Debtor.svc/json/DebtorSynchronization?dbName=2fP1N25PkIgL/D3kqJ/DETaVgM5hLD2GAQDUur5mY5YEiFp6GyuX2GebMFh0Do+7&uDId=iKNColFa+oztAVriouDfvMpoNDwsYn9H4aJxSVWFIWpqyPnE1k47C5VUkpntIVPr&isFullSync=true&lastUpdate=0&pageNo=1&perPage=1000'
$http.get(deburl).success(function(data) {
$cordovaSQLite.execute(db, "drop table debtor");
$cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS debtor (id integer primary key, debtordata text)");
debtorquery = "INSERT INTO debtor (debtordata) VALUES (?)";
$cordovaSQLite.execute(db, debtorquery, [data]).then(function(res) {
console.log("Data inserted successfully");
$cordovaSQLite.execute(db,"select * from debtor", []).then(function(tx ,res) {
console.log("Number of records "+res.rows.length);
console.log("Data "+angular.fromJson(res.rows.item(0).debtordata));
});
});
})
I have modified the code for your understanding, but it is not a correct way of doing it. We have to move all this code into an indiviual service and resolve promises for each transaction, that way our data integrity is maintained all over the app.
HI every thing is working now, data insert in sqlite db, but in mobile it is not working. i m unable to check db is created or not. can you explain how to check in device…