Ionic 2 Sqlite android : java.sql.SQLException: sqlite3_step failure: cannot rollback

563 Views Asked by At

I am new to Ionic, trying to build mobile app with offline support. I am trying to create the database using cordova sqlite plugin. I can see the database file in my emulator's data\data\package\data.db. Cannot execute any insert statement.

import { Component } from '@angular/core';
import { NavController, Platform } from 'ionic-angular';
import { SQLite, SQLiteObject } from '@ionic-native/sqlite';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {
  dbHandle : SQLiteObject;
  constructor(public navCtrl: NavController, private sqlite: SQLite, public plt: Platform) {
    this.plt.ready().then((readySource) => {
      console.log('Platform ready from', readySource);
      // Platform now ready, execute any required native code
      this.handleDbCreation(); 
    });

  }

  handleDbCreation() {
    this.sqlite.create({
      name: 'data.db',
      location: 'default'
    }).then((db: SQLiteObject) => {
      this.dbHandle = db;
      db.executeSql('create table danceMoves(name VARCHAR(32))', {})
        .then(() => {console.log('Executed SQL')
          this.insertDataIntoDB();
        })
        .catch(e => console.log(e));
    }).catch(e => console.log(e));
  }

  insertDataIntoDB(){
    this.dbHandle.executeSql("insert into danceMoves values(?)",['testing'])
    .then((resultSet)=>{
        console.log('resultSet.insertId: ' + resultSet.insertId);
        console.log('resultSet.rowsAffected: ' + resultSet.rowsAffected);
    })
    .catch((error)=>{
       console.log('SELECT error: ' + error.message);
    });  
  }
}

I am getting the below mentioned error.

D/SystemWebChromeClient(11475): file:///android_asset/www/plugins/cordova-sqlite-storage/www/SQLitePlugin.js: Line 179 : OPEN database: data.db - OK [INFO:CONSOLE(179)] "OPEN database: data.db - OK", source: file:///android_asset/www/plugins/cordova-sqlite-storage/www/SQLitePlugin.js (179) java.sql.SQLException: sqlite3_step failure: cannot rollback - no transaction is active at io.liteglue.SQLiteGlueConnection$SQLGStatement.step(SQLiteGlueConnection.java:135) at io.sqlc.SQLiteConnectorDatabase.executeSQLiteStatement(SQLiteConnectorDatabase.java:214) at io.sqlc.SQLiteConnectorDatabase.executeSqlBatch(SQLiteConnectorDatabase.java:114) at io.sqlc.SQLitePlugin$DBRunner.run(SQLitePlugin.java:340) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) at java.lang.Thread.run(Thread.java:841) SQLitePlugin.executeSqlBatch: Error=sqlite3_step failure: cannot rollback - no transaction is active java.sql.SQLException: sqlite3_step failure: cannot rollback - no transaction is active at io.liteglue.SQLiteGlueConnection$SQLGStatement.step(SQLiteGlueConnection.java:135) at io.sqlc.SQLiteConnectorDatabase.executeSQLiteStatement(SQLiteConnectorDatabase.java:214) at io.sqlc.SQLiteConnectorDatabase.executeSqlBatch(SQLiteConnectorDatabase.java:114) at io.sqlc.SQLitePlugin$DBRunner.run(SQLitePlugin.java:340) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) at java.lang.Thread.run(Thread.java:841) SQLitePlugin.executeSqlBatch: SQL Error code = 1 message = sqlite3_step failure: cannot rollback - no transaction is active

0

There are 0 best solutions below