angular - 删除表时,Ionic SQLite 无法读取未定义的属性“executeSql”
问题描述
我是 Angular 的新手,在将数据同步到服务器并面临这个问题之前,我使用 SQLite 将数据存储在本地。
我想在生成新表之前删除我的 SQLite DB 中的表,但是当我运行删除查询时会发生错误。这是我的代码:
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { SQLite, SQLiteObject } from '@ionic-native/sqlite';
@Injectable()
export class LocalProvider {
public db: SQLiteObject;
constructor(
public http: HttpClient,
public sql: SQLite
) {
console.log('Hello LocalProvider Provider');
}
GenerateDB() {
return new Promise((resolve, reject) => {
if (this.db != null) {
resolve(this.db);
} else {
this.sql.create({
name: 'localpriok.sql',
location: 'default'
}).then((db: SQLiteObject) => {
this.db = db;
this.C_equipment_parrent();
this.C_equipment();
this.C_equipment_parameter();
this.C_master_parameter();
this.C_master_area();
this.C_log_inspeksi();
resolve(this.db);
}).catch((e) => {
console.log(JSON.stringify(e));
reject(e);
});
}
});
}
// error happens here
async Truncate(TABLE) {
// let query = 'DELETE FROM ' + TABLE;
return new Promise((resolve, reject) => {
this.db.executeSql('DELETE FROM ' + TABLE, []).then((data) => {
resolve(data);
// alert('Execute SQL, ' + data);
}, (error) => {
reject(error);
// alert(JSON.stringify(error));
})
});
}
async Insert_multi_to(TABLE, DATA) {
this.Truncate(TABLE).then(data => {
alert(JSON.stringify(data));
});
await this.GenerateDB().then((db: SQLiteObject) => {
let query = this.GenerateInsertMultiData(TABLE, DATA);
console.log(query);
db.executeSql(query, [])
.then(() => console.log('Executed SQL'))
.catch(e => console.log('YANG ERROR : ', query + 'ERRORNYA : ' + JSON.stringify(e)));
});
}
有没有其他人遇到过这种情况,请帮助我。谢谢。
解决方案
推荐阅读
- java - 模拟 AmazonS3Client 没有任何依赖,如 s3mock 或 s3ninja
- php - PHP:为什么@var $foo 类有效而@var $this->foo 类无效?
- r - 使用数据表删除仅包含 NA 的列
- angular - 如何使用来自 component.ts 的参数创建 @angular/animations?
- android - RecyclerView Inside Recylerview,Inner RecyclerView Items在某些设备上没有完全显示
- electron - 如何在电子中设置 devTools 窗口位置
- wordpress - 根据主题wordpress更改主页
- css - 悬停时调整 SVG 圆圈的大小溢出:隐藏问题
- python - 不变的变量,即使它改变了
- self-hosting - 如何使自托管的预投标服务器与 AMP 一起使用?