在Android应用程序上找不到预先填充的db表来响应本机SQLite
我有一个非常简单的react原生应用程序,它应该从预先填充的数据库中读取数据在Android应用程序上找不到预先填充的db表来响应本机SQLite,android,react-native,sqlite,Android,React Native,Sqlite,我有一个非常简单的react原生应用程序,它应该从预先填充的数据库中读取数据 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 co
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);
});
});
如果我从项目中打开数据库,它会显示表和数据。我把数据放进了电脑
\android\app\src\main\assets\www和\android\app\src\main\assets\
我做错了什么
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":[]}]})