2017-09-05 65 views
0

我在Ionic中有非常簡單的代碼。我只是從ionicframwork文檔複製代碼。它目前沒有工作。我無法進行選擇或插入請求。這裏是我的代碼:java.sql.SQLException:sqlite3_step失敗:無法回滾 - 沒有事務處於活動狀態

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

昨天一切正常,今天我有一個錯誤:

09-05 18:48:46.298 20457-20703/io.ionic.starter V/SQLitePlugin: Android db implementation: built-in android.database.sqlite package 
09-05 18:48:46.298 20457-20704/io.ionic.starter V/info: Open sqlite db: /data/user/0/io.ionic.starter/databases/sub.db 
09-05 18:48:46.428 20457-20457/io.ionic.starter D/SystemWebChromeClient: file:///android_asset/www/plugins/cordova-sqlite-storage/www/SQLitePlugin.js: Line 179 : OPEN database: sub.db - OK 
09-05 18:48:46.428 20457-20457/io.ionic.starter I/chromium: [INFO:CONSOLE(179)] "OPEN database: sub.db - OK", source: file:///android_asset/www/plugins/cordova-sqlite-storage/www/SQLitePlugin.js (179) 
09-05 18:48:46.448 20457-20457/io.ionic.starter D/SystemWebChromeClient: file:///android_asset/www/cordova.js: Line 1223 : deviceready has not fired after 5 seconds. 
09-05 18:48:46.448 20457-20457/io.ionic.starter I/chromium: [INFO:CONSOLE(1223)] "deviceready has not fired after 5 seconds.", source: file:///android_asset/www/cordova.js (1223) 
09-05 18:48:46.488 20457-20457/io.ionic.starter D/CordovaWebViewImpl: onPageFinished(file:///android_asset/www/index.html) 
09-05 18:48:46.528 20457-20704/io.ionic.starter W/System.err: java.sql.SQLException: sqlite3_step failure: cannot rollback - no transaction is active 
09-05 18:48:46.528 20457-20704/io.ionic.starter W/System.err:  at io.liteglue.SQLiteGlueConnection$SQLGStatement.step(SQLiteGlueConnection.java:135) 
09-05 18:48:46.528 20457-20704/io.ionic.starter W/System.err:  at io.sqlc.SQLiteConnectorDatabase.executeSQLiteStatement(SQLiteConnectorDatabase.java:214) 
09-05 18:48:46.528 20457-20704/io.ionic.starter W/System.err:  at io.sqlc.SQLiteConnectorDatabase.executeSqlBatch(SQLiteConnectorDatabase.java:114) 
09-05 18:48:46.528 20457-20704/io.ionic.starter W/System.err:  at io.sqlc.SQLitePlugin$DBRunner.run(SQLitePlugin.java:340) 
09-05 18:48:46.528 20457-20704/io.ionic.starter W/System.err:  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) 
09-05 18:48:46.528 20457-20704/io.ionic.starter W/System.err:  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) 
09-05 18:48:46.528 20457-20704/io.ionic.starter W/System.err:  at java.lang.Thread.run(Thread.java:818) 
09-05 18:48:46.528 20457-20704/io.ionic.starter V/executeSqlBatch: SQLitePlugin.executeSql[Batch](): Error=sqlite3_step failure: cannot rollback - no transaction is active 
09-05 18:48:46.528 20457-20704/io.ionic.starter W/System.err: java.sql.SQLException: sqlite3_step failure: cannot rollback - no transaction is active 
09-05 18:48:46.528 20457-20704/io.ionic.starter W/System.err:  at io.liteglue.SQLiteGlueConnection$SQLGStatement.step(SQLiteGlueConnection.java:135) 
09-05 18:48:46.528 20457-20704/io.ionic.starter W/System.err:  at io.sqlc.SQLiteConnectorDatabase.executeSQLiteStatement(SQLiteConnectorDatabase.java:214) 
09-05 18:48:46.528 20457-20704/io.ionic.starter W/System.err:  at io.sqlc.SQLiteConnectorDatabase.executeSqlBatch(SQLiteConnectorDatabase.java:114) 
09-05 18:48:46.528 20457-20704/io.ionic.starter W/System.err:  at io.sqlc.SQLitePlugin$DBRunner.run(SQLitePlugin.java:340) 
09-05 18:48:46.528 20457-20704/io.ionic.starter W/System.err:  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) 
09-05 18:48:46.528 20457-20704/io.ionic.starter W/System.err:  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) 
09-05 18:48:46.528 20457-20704/io.ionic.starter W/System.err:  at java.lang.Thread.run(Thread.java:818) 
09-05 18:48:46.528 20457-20704/io.ionic.starter V/executeSqlBatch: SQLitePlugin.executeSql[Batch](): SQL Error code = 1 message = sqlite3_step failure: cannot rollback - no transaction is active 
09-05 18:48:46.538 20457-20457/io.ionic.starter D/SystemWebChromeClient: file:///android_asset/www/build/vendor.js: Line 106774 : Ionic Native: deviceready event fired after 4291 ms 
09-05 18:48:46.538 20457-20457/io.ionic.starter I/chromium: [INFO:CONSOLE(106774)] "Ionic Native: deviceready event fired after 4291 ms", source: file:///android_asset/www/build/vendor.js (106774) 
09-05 18:48:46.538 20457-20703/io.ionic.starter I/App: WARNING: Back Button Default Behavior will be overridden. The backbutton event will be fired! 
09-05 18:48:46.598 20457-20457/io.ionic.starter D/SystemWebChromeClient: file:///android_asset/www/build/main.js: Line 55 : Executed SQL 
09-05 18:48:46.598 20457-20457/io.ionic.starter I/chromium: [INFO:CONSOLE(55)] "Executed SQL", source: file:///android_asset/www/build/main.js (55) 

回答

0

我想類似的事情最近發生在我身邊。 我在添加Platform ready驗證後爲我工作。一些與此類似:

constructor(public nav: NavController, public platform: Platform, public sqlite: SQLite ,...) { 
    let _this = this; //Not sure if this is needed 
    platform.ready().then(() => { 

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

我希望這可以幫助你

0

你應該調用close SQLiteObject對象實例()方法。

this.sqlite.create({ 
      name: 'sub.db', 
      location: 'default' 
     }) 
      .then((db:SQLiteObject) => { 
       db.executeSql('create table danceMoves(name VARCHAR(32))',{}) 
        .then(() => { 
         console.log('Executed SQL'); 
         db.close(); // <--------------- 
        }) 
        .catch((e) => console.log(e)); 
      }) 
      .catch((e) => console.log(e)); 

希望它有助於

https://ionicframework.com/docs/native/sqlite/

相關問題