首页 > 解决方案 > 在 Android 应用程序上找不到带有预填充数据库表的 React-Native SQLite

问题描述

我确实有一个非常简约的 react-native 应用程序,它应该从预先填充的数据库中读取数据。

var SQLite = require('react-native-sqlite-storage');
SQLite.DEBUG(true);
SQLite.enablePromise(false);

const db = SQLite.openDatabase({
  name: 'config.db',
  location: 'default'
}, () => {
console.log('db connection success') 
}, () => {
console.log('db connection error')
});

控制台说:

db connection success

如果我运行一个 qry,我总是会收到一个找不到表的错误:

db.transaction((tx) => {
  console.log('TX');
  tx.executeSql('SELECT * FROM test',
  [],
  (tx, results) => {
    console.log(results)
    var temp = [];
    for (let i = 0; i < results.rows.length; ++i)
      temp.push(results.rows.item(i));
      console.log(temp);
  });
});

错误:

SQLite.backgroundExecuteSqlBatch({"dbargs":{"dbname":"config.db"},"executes":[{"qid":1111,"sql":"BEGIN","params":[]},{"qid":1111,"sql":"SELECT * FROM tbl_user","params":[]}]})
    Error handler not provided:  {"code": 0, "message": "no such table: tbl_user(code 1 SQLITE_ERROR): , while compiling: SELECT * FROM tbl_user"}
    warning - exception while invoking a callback:{"code":0,"line":116571,"column":27,"sourceURL":"http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false"}
    SQLite.backgroundExecuteSqlBatch({"dbargs":{"dbname":"config.db"},"executes":[{"qid":1111,"sql":"ROLLBACK","params":[]}]})

如果我从我的项目中打开数据库,它会显示表格和数据。我将数据放入 \android\app\src\main\assets\www 和 \android\app\src\main\assets\

我究竟做错了什么?

标签: androidreact-nativesqlite

解决方案


推荐阅读