Hello guys,
I trying to integrate sqlite in ionic framework. followed each every step mentioned in the blow blog
I was able to create DB and was able to insert data in it.
However when trying to select some data I got undefined erro
My code is as below
in app.js
var LBdb = null;
in .run method
LBdb = $cordovaSQLite.openDB({ name: “lbite.db” , bgType: 1});
$cordovaSQLite.execute(LBdb, “CREATE TABLE IF NOT EXISTS tbl(id )”)
in controller I am acessing it as below
var countQuery = “select id from tbl”;
$cordovaSQLite.execute(LBdb, countQuery).then(function(res){
return res;
Upon searching I came to know that Ionic first loads controllers and services which causes this problem.
Please let me know if you have workaround for this
Regards,
Suhas
Hi,
Thanks for your response. I managed to solve the problem. However I came across new problems when trying to bind data to the list from sqlite. Do you have any example of it
here is my code
var countQuery = “select id,name,image_url,category,price from tblProduct”;
$cordovaSQLite.execute(LBdb, countQuery).then(function(result){
$scope.items = result.rows
}
however above code does not worked hence i stringified as below
if(result.rows.length > 0){
var itemsColl = [];
for (var i = 0; i < result.rows.length; i++) {
itemsColl[i] = result.rows.item(i);
};
items = JSON.stringify(itemsColl);
console.log("scope of items is " + items);
return items;
}
Thanks for the inputs. I’ll try this, however the real issue is setting scope variable. I guess scope variable is not updating somehow and that’s why view is not rendering properly
Regards,
Suhas
Finally got it working, earlier I have created separate file for db interaction and returning array from it still dont know why angular was not returning it might be some promise related issues.
Hence I moved code to controller and called function when angular loads, this is working now although as a workaround and not the way I want it.
First I need to understand asynchronous stuff and understand what a promise, deffer, digest and apply means then might be I will achieve what I want to