Ionic @电容器-社区/sqlite:错误:查询失败:选择SQL:查询全部:无此类表格:初始化应用程序时使用sqlite_sequence(Web模式)

owfi6suc  于 2023-03-06  发布在  Ionic
关注(0)|答案(1)|浏览(171)

更新:

因此,我现在仔细地比较了github启动器和我的启动器,我发现了程序在数据库方面两种状态不同的第一行代码:
在开放数据库(...)中的sqlite. service. ts中:

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());

在这里你可以看到表格列表。值有两个所需的表格:

这里u不能看到表格列表.值有两个所需的表格:

=〉所以这个错误可能是因为这个. sqliteConnection. createConnection()没有为我做正确的事情。但是这不是我的方法,而是库的一部分...
我跟随这个初学者应用程序,它展示了如何使用ionic-cap-sqlite:https://github.com/jepiqueau/ionic-angular-sqlite-starter,并将所有的东西集成到我的应用程序中。实际上,我只采取了员工部门的一部分,并取代了这两个实体与我的两个,我没有采取任何职位类别的代码。
我分叉了启动器项目,也完全摆脱了加密/解密的东西,没有它,所有仍然工作(我想修剪错误,以尽可能少的代码)
现在在init中,我得到了以下内容:Error: Query failed: SelectSQL: queryAll: no such table: sqlite_sequence
我读到:https://stackoverflow.com/a/17736785/20009330并检查我的序列,我的upgrade语句(创建db表)看起来如下所示:

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();
}`

这一切都是在初学者项目中完成的,在那里它工作,而不是在我的项目中做它。
我很乐意提供更多的代码,但我不能分享我的整个项目,因为我想。

xytpbqjk

xytpbqjk1#

原来我的CapacitorSQLitePlugin.addUpgradeStatement方法失败了(没有创建表),因为我的升级sql语句中有一个愚蠢的错误(我将变量标记为外键,但我忘记将它也声明为自己的变量)。
但是addUpgradeStatement方法没有抛出错误,随后的查询失败。

相关问题