Hello,
Could you some one help to display data stored in sqlite table to list using ng-repeat. This is working fine for json strings. however not working for sqlite.
Regards,
Suhas
Hello,
Could you some one help to display data stored in sqlite table to list using ng-repeat. This is working fine for json strings. however not working for sqlite.
Regards,
Suhas
what are you using for SQLite wrapper ? javascript ?
check the object structure returned by the SQLite
post the code for better understanding of the code
Hi Harshit,
I canāt check the object structure since I am executing it in emulator. However I converted sqllite data to json form usingstringify and assigned it to scope variable however the code is not working as ui is not rendering. I have checked the logs which shows stringify scope variable.
You should not be assigning the string to scope variable, directly assign the object returned by the Cordova function and not the stringified string⦠If that still doesnāt work, please provide the code and the stringified stringā¦
Hi Harshit,
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;
}
this is also not working
HTML code is
{{ item.name }}
{{ item.category}}
<br />
<h4 class="price"> {{ item.price }}</h4>
<i class="icon ion-ios7-arrow-forward"></i>
</a>
can you stringify the result object and post the output ?
JSON.stringify(result)
also on eclipse check the error you are getting in logcat console
also to access the object in array, u access it as follows
result.rows[i];
and not as result.rows.item(i);
Hi Harshit,
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
Thank for helping me out
Regards,
Suhas
Hi Harshitgoel96,
I am facing the same problem here is my code.
.controller('databaseCtrl', function($scope, $cordovaSQLite){
var db= $cordovaSQLite.openDB({name: "mydb.db"});
var query=" SELECT * FROM song" ;
$scope.results=[];
$cordovaSQLite.execute(db, query, []).then(function(result) {
if(result.rows.length >0){
for(var i=0; i<result.rows.length; i++){
$scope.results.push(result.rows[i]);
}
alert(JSON.stringify($scope.results));
}
else{
console.log("####console######## NO results found #######"+"Table record #: ");
}
}, function(error){
console.log(error);
})
})
instead of
$scope.results.push(result.rows[i]);
use
$scope.results.push(result.rows.items(i));
Regards,
Suhas
Any updates on this? Are the codes working? Thank you in advance.
Just want to share this to you. I think this can help.
indent preformatted text by 4 spaces
How about this? It is not working though
I need help in this tooā¦
$scope.select = function (lastname) {
$scope.statusMessage = "Start Fetching "+ $scope.lname;
var query = "SELECT firstname, lastname FROM people WHERE lastname = ?";
$cordovaSQLite.execute(db, query, [$scope.lname]).then(function (res) {
if (res.rows.length > 0) {
for (var i = res.rows.length - 1; i <= 0; i++) {
$scope.people.push({
fname:res.rows.item(i).firstname,
lname:res.rows.item(i).lastname
});
// $scope.statusMessage = "SELECTED -> " + res.rows.item(i).firstname + " " + res.rows.item(i).lastname;
};
$scope.ppl=people;
} else {
$scope.statusMessage = "No results found";
}
}, function (err) {
console.error(err);
});
}
Thanks a Million. It works like charm.
It would be '$scope.results.push(result.rows.item(i)); Note: āitemā instead of āitemsā.
Hiiā¦
I m trying to open my pre defined database in ionicā¦which i placed in www directoryā¦but when ever i run the app i m unable to access tabels of my db so plz buddies if u have any solution plz help me outā¦i m unable to load my databaseā¦hope u got my problemā¦
Hallo every one, i have 2 problem to display data from sqlite.
1. How to insert data from json to sqlite
2. How to display sqlite data on listview
i have try the code above, but i still stack ?
any one can help me ?
thank you
Try with this example: https://github.com/jdnichollsc/Ionic-Starter-Template
Regards, Nicholls
how can i bind select query result to an array without for loop to improve my speed?
ts
db.executeSql("SELECT * FROM usernameList", []).then((data) => {
if (data.rows.length > 0) {
for (var i = 0; i < data.rows.length; i++) {
console.log(data.rows.item(i));
this.list_domain=data.rows.item(i).domain_name;
this.list_name=data.rows.item(i).name;
this.list_elements.push({
domain:this.list_domain,
name:this.list_name
});
}
console.log(this.list_elements);
}
});
html
<ion-list>
<ion-item *ngFor="let data of list_elements">
{{data.domain}}
{{data.name}}
</ion-item>
</ion-list>