【问题标题】:Cannot read property 'open' of undefined when opening react-native-sqlite-storage database from ios从 ios 打开 react-native-sqlite-storage 数据库时无法读取未定义的属性“打开”
【发布时间】:2017-06-18 01:36:41
【问题描述】:

我正在尝试使用 react-native-sqlite-storage 与本地数据库一起使用 react native,对于 ios。

var SQLite = require('react-native-sqlite-storage');
var db = []; 

export default class DataBase {
  constructor () {
    db = SQLite.openDatabase("eventHelper.db", "1.0", "EventHelper", 200000, this.openCB, this.errorCB);
  }

  errorCB(err) {
    console.log("SQL Error: " + err);
  }

  successCB() {
    console.log("SQL executed fine");
  }

  openCB() {
    console.log("Database OPENED");
  }
}

但我收到以下错误消息:无法读取未定义的属性“打开”。 我不知道 openDatabase 是如何工作的,我还没有创建数据库。我不确定我是否应该首先创建数据库,以及如何创建数据库,或者如果数据库不存在,openDatabase 是否会这样做。

我寻找了这个问题,并尝试了这里建议的解决方案https://github.com/andpor/react-native-sqlite-storage/issues/64 - 卸载 react-native-sqlite-storage - 删除了 node_modules 文件夹 - npm 安装 - npm install --save react-native-sqlite-storage - rnpm 链接

但我的构建失败

我们将不胜感激任何建议。谢谢!

【问题讨论】:

    标签: ios sqlite react-native


    【解决方案1】:

    一个简单的使用示例(目前我在生产应用中使用它)

    var SQLite = require('react-native-sqlite-storage');
    var db = SQLite.openDatabase({name : "db.sqlite", location: 'default'});
    
    db.executeSql("SELECT * FROM users WHERE userName=?",['user1'],
                (results) => {
                  console.log(results);
                },
                (err) => {
                  console.log(err);
                }
                );
    

    【讨论】:

    • 我对 react native 中的 sqlite 有一些问题,你能帮帮我吗?
    【解决方案2】:

    安装 SQLite 插件后是否重新运行 react-native run-ios ? 我遇到了同样的错误并已修复,希望对您有所帮助

    【讨论】:

      猜你喜欢
      • 2015-08-18
      • 2017-12-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-28
      • 2017-11-09
      • 2017-01-02
      • 2011-05-01
      相关资源
      最近更新 更多