Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error while trying run andriod app sqllite DB

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;
 }

}

like image 625
Avdhut Avatar asked Nov 24 '25 13:11

Avdhut


1 Answers

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.

like image 141
Avdhut Avatar answered Nov 27 '25 10:11

Avdhut



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!