I'm building an ionic app with a SQlite database. I can already put data in the database, but when I run a simple query to get data, I get really weird feedback.
My simple code
this.databaseService.execQuery('SELECT * FROM timelog WHERE id = ? ORDER BY id DESC',[this.ongoingTimelog.id])
.then((data) => {
console.log(data);
debugger;
});
execQuery(query: string, params?: Array<string | number>): Promise<any> {
return new Promise((resolve, reject) => {
if (!query) {
resolve();
}
this.db.executeSql(query, params)
.then((result: any) => {
resolve(result);
})
});
}
So normally I would suspect (as I get on my pc envoirement) the data to be like data.rows[0].id... But on my tablet I get the following: data on phone
Does anybody have any idea why i get something completely different and how I can get the correct data?
Thanks in advance!!
What you see is the javascript wrapper of the SQLite. That wrapper make possible to talk with js and be common for Android and iOS.
Your data is there, the screenshot shows you have one item. To access you need:
this.databaseService.execQuery('SELECT * FROM timelog WHERE id = ? ORDER BY id DESC',[this.ongoingTimelog.id])
.then((data) => {
console.log(data.rows.item(0));
debugger;
});
Needs data.rows.item(0).id instead of data.rows[0].id
Check this sample app it could help. cordova-sqlite-storage-starter-app