android - 在 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\
我究竟做错了什么?
解决方案
推荐阅读
- c# - c#: Datagrid:通过 DataTriggers 更改选择的前景色
- c# - 另一种让鼠标点击的方法?
- javascript - 网页将在 Microsoft Edge 中加载外部 CSS 和 JS,但不会在 Chrome 中
- python - 我下载了漏洞利用脚本,当尝试运行它时,它给了我一个错误
- python - 为链接抓取表格,从每个链接获取数据,并对许多页面执行相同操作(分页)
- unit-testing - Mockito junit 测试不起作用-@mockBean 模拟的 bean 为空
- php - 提交表单时如何计算以相同前缀开头的字段名称?
- sql - 验证 SQL 查询
- ios - 在 SwiftUI 中暂停通知发布者
- python - 如何使用上下文在同一行中定义的上下文设置默认值?