我是Ionic的新手,尝试使用离线支持构建移动应用。我正在尝试使用cordova sqlite
插件创建数据库。我可以在我的模拟器data\data\package\data.db
中看到数据库文件。无法执行任何insert语句。
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);
});
}
}
我收到了下面提到的错误。
d / SystemWebChromeClient(11475): 文件:///android_asset/www/plugins/cordova-sqlite-storage/www/SQLitePlugin.js: 第179行:OPEN数据库:data.db - 好的 [INFO:CONSOLE(179)]" OPEN数据库:data.db - OK",来源:file:///android_asset/www/plugins/cordova-sqlite-storage/www/SQLitePlugin.js (179) java.sql.SQLException:sqlite3_step失败:无法回滚 - 没有事务处于活动状态 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) 在java.lang.Thread.run(Thread.java:841) SQLitePlugin.executeSqlBatch:错误= sqlite3_step失败:无法回滚 - 没有事务处于活动状态 java.sql.SQLException:sqlite3_step失败:无法回滚 - 没有事务处于活动状态 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) 在java.lang.Thread.run(Thread.java:841) SQLitePlugin.executeSqlBatch:SQL错误代码= 1消息= sqlite3_step失败:无法回滚 - 没有事务处于活动状态