我正在努力使用库react-native-sqlite-storage
我使用的是android模拟器,所以我将我的users.db文件放在'android/app/src/main/assets/users.db‘中。这是文件users.db的图像
我还运行了命令npx react-native link来创建链接,我使用的是带有自动链接的react-native版本6.0以上的版本
不幸的是,我得到了这个错误:error not connect database
这是我的代码,有没有人可以帮我?感谢您的宝贵时间!
import React, {Component} from 'react'
import {View, Text, Alert} from 'react-native'
import SQLite from 'react-native-sqlite-storage'
export default class App extends Component {
constructor(props) {
super(props)
SQLite.openDatabase({name:'users', createFromLocation:1}, this.connected, this.failed)
}
connected= () =>{
Alert.alert('Connected with success !')
}
failed= (e) =>{
Alert.alert('Something went wrong !', `${e}`)
}
render(){
return(
<View>
<Text>Testing SQLite</Text>
</View>
)
}
}发布于 2020-08-20 02:37:25
因此,我所做的是将属性createFromLocation更改为数字2,当您这样做时,系统会创建它自己的数据库,而这个数据库是空的,所以您只需要创建表并以您想要的方式使用它!不幸的是,我没有设法使用我的旧数据库,但是使用这个新的数据库解决了我的问题!
发布于 2020-12-14 23:52:26
你需要把你的数据库放到assets/www文件夹中才能正常工作。
发布于 2021-05-10 21:31:09
在我从设备上完全卸载应用程序并使用npx react-native run-android从头开始重新安装之后,预先填充的数据库是只读的。
当应用程序已经在设备上时,简单地重新加载是不够的。
https://stackoverflow.com/questions/62963989
复制相似问题