【问题标题】:Read data from existing SQLite database through ionic and angular通过 ionic 和 Angular 从现有 SQLite 数据库中读取数据
【发布时间】:2021-03-11 01:09:03
【问题描述】:

我是 ionic 应用程序开发的新手。
打算用 ionic、angular 和 sqlite 开发一个字典应用程序。
SQLite db 文件已准备好所需的表,应用程序需要使用 db 文件进行部署。

作为第一步,我如何从 db 文件中读取数据?

我应该使用 SQLite https://ionicframework.com/docs/native/sqlite
或者 SQLite 搬运工 https://ionicframework.com/docs/native/sqlite-porter

let db = (<any>window).openDatabase('dictionary', '1.0', 'dictionary', 1 * 1024);
    this.http.get('../assets/database/dictionary.db', { responseType: 'text' })
          .subscribe(sql => {
            this.sqlitePorter.importSqlToDb(db, 'select * from terms')
              .then(() => console.log('Imported'))
              .catch(e => console.error(e));
          }, error => {
            console.log('error: ' + JSON.stringify(error));
          });

我尝试了上面的编码,但它在 Android Studio 模拟器上给了我 404 not found 错误。

【问题讨论】:

    标签: angular sqlite ionic-framework


    【解决方案1】:

    导入文件应该是 .sql 而不是 .db。由于 SqliteDbCopy 存在电容复制问题,我使用了 SQLitePorter

    最终的解决方案是使用电容、SQLitePorter和.sql文件来导入数据。

    【讨论】:

    • 如果您有补充问题,请将其作为新问题提出。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多