I am trying to create an app using Angular and ionic with cordova and Sqllite DB. When trying to create the DB gets created but gives below error while runing on device :
ERROR Error: Uncaught (in promise): Object: {"rows":
{"length":18},"rowsAffected":0}
The DB is created but I also get the error and then no operation can be performed for the database. Following is the code I am using to create DB.
export class AppDatabaseService {
private database: SQLiteObject;
constructor(private sqlite: SQLite) {
console.log('Working here 2');
this.createDb();
}
private createDb(): void {
this.sqlite.create({
name: 'glucoMonitor.db',
location: 'default'
}).then((db: SQLiteObject) => {
db.executeSql('CREATE TABLE PERSONRECORD (' +
'id integer PRIMARY key AUTOINCREMENT,' +
'firstname text,' +
'lastname text,' +
'dob text,' +
'height text' +
')')
.then(_res => console.log('Db Table created'))
.catch(e => console.log('error occured' + e));
db.executeSql('CREATE TABLE SugarLevelMonitor (' +
'id integer PRIMARY key AUTOINCREMENT, ' +
'recordtime text,' +
'sugarlevel integer,' +
'recorddate text,' +
'personid integer' +
')')
.then(_res => console.log('Db Table created'))
.catch(e => console.log('error occured' + e));
db.executeSql('CREATE TABLE WeightMonitor (' +
'id integer PRIMARY key AUTOINCREMENT, ' +
'weightLevel REAL,' +
'recorddate text,' +
'recordtime DATETIME' +
')')
.then(_res => console.log('Db Table created'))
.catch(e => console.log('error occured' + e));
this.database = db;
}).catch(e => console.log('error occured' + e));
}
public getDatabase() {
return this.database;
}
}
The given error was coming due to cordova run android --device
It was not re-building the application. I needed to execute cordova build android
to make app work properly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With