gpt4 book ai didi

javascript - ionic SQLite ;无法打开数据库

转载 作者:行者123 更新时间:2023-11-30 13:56:27 25 4
gpt4 key购买 nike

我想将我的 ionic 应用程序与数据库相关联,但我遇到了一些错误。我正在使用 google chrome DevTools 在 android 设备上运行该应用程序以查看背后发生的情况。

查看 createDatabase() 函数和我遇到的错误。

createDatabase() {
this.plt.ready().then(() => {
if (this.plt.is('cordova')) {
this.sqlite = new SQLite();
this.sqlite.create({
name: 'ocp_database_fuits.db',
location: 'default'
}).then((db: SQLiteObject) => {
this.database = db;
this.createTables();
}).catch(e => {
console.log(e);
});
}
});
}

OPEN database: ocp_database_fuits.db

SQLitePlugin.js:197 OPEN database: ocp_database_fuits.db

FAILED, aborting any pending transactions main.js:686 Error: Could not open database

  at newSQLError (SQLitePlugin.js:26)
at SQLitePlugin.js:199
at Object.callbackFromNative (cordova.js:290)
at <anonymous>:1:9

最佳答案

好的。为了解决您的问题,请按照以下步骤操作

npm update
npm run build
ionic cordova plugin rm cordova-plugin-sqlite-2

之后,在您的数据库文件中更改它

createDatabase(): void {
this.plt.ready().then(() => {
if (this.plt.is('cordova')) {
this.sqlite = new SQLite();
this.sqlite.create({
name: 'ocp_database_fuits.db',
location: 'default'
}).then((db: SQLiteObject) => {
this.database = db;
this.createUserTable(this.database);
this.createPathTable(this.database);
}).catch(e => {
console.log(e);
});
}
});
}

还有

createUserTable(db): void {
// const d: SQLiteObject;
db.executeSql('CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY AUTOINCREMENT, username TEXT, pass TEXT)', [])
.then(() => {
console.log('table users created');
}).catch(e => {
console.log('error in createUserTable function');
console.log(e);
});
}

createPathTable(db): void {
db.executeSql('CREATE TABLE IF NOT EXISTS paths (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, type TEXT, points TEXT', [])
.then(() => {
console.log('table paths created');
}).catch(e => {
console.log('error in createPathTable function');
console.log(e);
});
}

关于javascript - ionic SQLite ;无法打开数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57193210/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com