- SDK Version:35.0.0
- Platforms(Android/iOS/web/all):Android
Expo sqlite after building on device not working
Error
{
“line”:639, “column”:1161, “sourceUrl”:‘…’
}
App.js
FileSystem.getInfoAsync(`${FileSystem.documentDirectory}SQLite/testdb.db`).then(file => {
alert(JSON.stringify(file));
if (file.exists === false) {
FileSystem.downloadAsync(
Asset.fromModule(require('./assets/testdb.db')).uri,
`${FileSystem.documentDirectory}SQLite/testdb.db`
)
}
});
HomeScreen.js
import * as WebBrowser from 'expo-web-browser';
import React, { Component } from 'react';
import FooterLogo from '../assets/images/s1200.jpg'
import { withNavigation } from 'react-navigation';
import { NavigationActions, StackActions } from 'react-navigation';
import * as SQLite from 'expo-sqlite';
import {
Image,
Platform,
StyleSheet,
Text,
View,
} from 'react-native';
import { Button } from 'react-native-elements';
const db = SQLite.openDatabase(`testdb.db`);
class HomeScreen extends Component {
constructor(props) {
super(props);
}
componentDidMount() {
db.transaction(
tx => {
tx.executeSql("SELECT * FROM questions;", [], (_, { rows }) => {
alert(JSON.stringify(rows));
}, (t, error) => {
alert(JSON.stringify(t));
alert(JSON.stringify(error));
alert("Bog'lanishda xatolik, Iltimos qayta harakat qilib ko'ring! Xatolik kodi: 1001");
})
}, (t, error) => {
alert(JSON.stringify(t));
alert(JSON.stringify(error));
alert("Bog'lanishda xatolik, Iltimos qayta harakat qilib ko'ring! Xatolik kodi: 1002");
}, (t, error) => {
alert(JSON.stringify(t));
alert(JSON.stringify(error));
console.log("N1")
}, () => {
console.log("N1")
});
//this.props.navigation.dispatch(resetAction)
}
render() {
return (
<View style={styles.container}>
<View style={styles.btnCenterContainer}>
<Text style={styles.headTextCenter}>
Jismoniy madaniyat nazariyasi va metodikasi fanidan darajali testlar
</Text>
<View
style={[styles.containerButtons]}>
<Button
containerStyle={styles.btn}
onPress={() => {
this.props.navigation.navigate('TestViewScreen', { level: 1 });
}}
title="Brinchi daraja"
/>
<Button
containerStyle={styles.btn}
onPress={() => {
this.props.navigation.navigate('TestViewScreen', { level: 2 });
}}
title="Ikkinchi daraja"
/>
<Button
title="Uchunchi daraja"
containerStyle={styles.btn}
onPress={() => {
this.props.navigation.navigate('TestViewScreen', { level: 3 });
}}
/>
</View>
</View>
<View style={styles.tabBarInfoContainer}>
<View>
<Image source={FooterLogo} />
</View>
</View>
</View>
);
}
}
HomeScreen.navigationOptions = {
header: null,
};
export default withNavigation(HomeScreen);
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
paddingTop: 30,
},
btnCenterContainer: {
alignItems: 'center',
marginHorizontal: 50,
},
headTextCenter: {
marginVertical: 20,
fontSize: 24,
color: "#155d61",
fontWeight: "600",
textAlign: 'center'
},
btn: {
marginTop: 20
},
containerButtons: {
backgroundColor: 'rgba(0,0,0,0.00)',
width: '100%',
height: '100%',
paddingHorizontal: 4,
},
tabBarInfoContainer: {
position: 'absolute',
bottom: 0,
left: 0,
right: 0,
...Platform.select({
ios: {
shadowColor: 'black',
shadowOffset: { width: 0, height: -3 },
shadowOpacity: 0.1,
shadowRadius: 3,
},
android: {
elevation: 20,
},
}),
alignItems: 'center',
backgroundColor: '#fbfbfb',
paddingVertical: 0,
},
tabBarInfoText: {
fontSize: 17,
color: 'rgba(96,100,109, 1)',
textAlign: 'center',
},
});