Home > Enterprise >  SQLite Query has more than 1 row but keeps throwing exceptions - Angular, Ionic, Android
SQLite Query has more than 1 row but keeps throwing exceptions - Angular, Ionic, Android

Time:01-02

I have a Ionic Angular applications (Android build)

I have the following:

  getAllUsers() {
    return this.dbInstance.executeSql(`SELECT * from ${this.db_table}`)
      .then((data) => {
        if (data.rows.length > 0) {
          for (let i = 0; i < data.rows.length; i  ) {
            console.log('hello world');
            console.log(JSON.stringify(data.rows.item(i)));
          }
        }
      }).catch(e => {
        console.log(JSON.stringify(e));
      });
  }

When I call getAllUsers an exception is automatically thrown with the following console log in android studio

2021-12-30 17:50:32.831 25077-25077/io.ionic.starter I/Capacitor/Console: File: http://localhost/src_app_login_login_module_ts.js - Line 421 - Msg: {"rows":{"length":3},"rowsAffected":0}

This is a log of the query from the console:

2021-12-30 17:50:32.815 25077-25292/io.ionic.starter V/Capacitor/Plugin: To native (Cordova plugin): callbackId: SQLitePlugin1622878251, service: SQLitePlugin, action: backgroundExecuteSqlBatch, actionArgs: [{"dbargs":{"dbname":"userParameters.db"},"executes":[{"sql":"SELECT 1","params":[]},{"sql":"SELECT * from userParametersTable","params":[]}]}]

I am wondering why this behaviour is happening and how to fix this issue.

Thanks

CodePudding user response:

The problem was I needed to include the parameters (which used to be optional so like this:

    return this.dbInstance.executeSql(`SELECT * from ${this.db_table}`, [])

instead of

   return this.dbInstance.executeSql(`SELECT * from ${this.db_table}`)
  • Related