@capacitor-community/sqlite网页模式初始化报错:sqlite_sequence表不存在
问题排查记录与求助
更新:
我正在对比可正常运行的GitHub Starter项目和我的项目,找到了数据库状态差异的第一处代码:
在sqlite.service.ts的openDatabase(...)方法中:
db = await this.sqliteConnection .createConnection(dbName, encrypted, mode, version, readonly); } await db.open(); console.log('HERE: the .values property: my program has 0 tables, the working program has 2 tables: ', db.getTableList());
- 正常运行的应用:
table list.values包含两个预期的表 - 我的应用:
table list.values没有预期的两个表
推测错误原因可能是this.sqliteConnection.createConnection()未正常工作,但该方法属于库自带,并非我自定义的方法。
我参照展示ionic-cap-sqlite用法的Starter应用进行集成,仅替换了employee-department相关实体为自定义实体,未使用posts-category相关代码。我复刻了该Starter项目并移除了加密/解密功能,移除后Starter仍可正常运行(目的是精简代码定位错误)。
现在应用初始化时出现错误:
Error: Query failed: SelectSQL: queryAll: no such table: sqlite_sequence
我检查了序列配置,数据库升级语句如下:
export const mapModeLocationVersionUpgrades = [ { toVersion: 1, statements: [ `CREATE TABLE IF NOT EXISTS map ( id integer PRIMARY KEY AUTOINCREMENT NOT NULL, );`, `CREATE TABLE IF NOT EXISTS mode ( id integer PRIMARY KEY AUTOINCREMENT NOT NULL, FOREIGN KEY (mapId) REFERENCES map (id) );`, ] }, ]
错误发生在执行这段代码时:
const isData = await this.mDb.query("select * from sqlite_sequence");
该代码位于:
async initializeDatabase() { // create upgrade statements await this.sqliteService // NOTE: this initializes .addUpgradeStatement({ database: this.databaseName, upgrade: this.versionUpgrades}); // create and/or open the database await this.openDatabase(); this.dbVerService.set(this.databaseName,this.loadToVersion); const isData = await this.mDb.query("select * from sqlite_sequence"); // create database initial data if(isData.values!.length === 0) { await this.createInitialData(); } if( this.sqliteService.platform === 'web') { await this.sqliteService.sqliteConnection.saveToStore(this.databaseName); } await this.getAllData(); }
我通过app.module.ts中的以下代码在应用初始化时调用该方法:
export function initializeFactory(init: InitializeAppService) { return () => init.initializeApp(); }
所有操作均与Starter项目一致,但我的项目出现错误。可提供更多代码,但无法分享整个项目。
内容的提问来源于stack exchange,提问作者Felix Olszewski
相关产品推荐
相关产品推荐

