我在Ionic中有非常简单的代码。我只是从ionicframwork docs复制代码。目前还没有工作。我无法进行选择或插入请求。这是我的代码:
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 :(得分:0)
我觉得最近发生了类似的事情。 添加平台就绪验证后,它对我有用。类似的东西:
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));
});
}
我希望这可以帮到你
答案 1 :(得分:0)
你应该调用SQLiteObject对象实例的close()方法。
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));
希望有所帮助