Here I created a table called account. But when I try to insert data into it ,it shows an error
import React, { Component } from 'react'
import { AsyncStorage, Text, View, TextInput, StyleSheet, Button } from 'react-native'
import Expo, { SQLite } from 'expo';
const db = SQLite.openDatabase('wallet');
class AsyncStorageExample extends Component {
state = {
'balance': 0,
'value':0,
'sourceName' :'',
}
componentDidMount() {
db.transaction(tx => {
tx.executeSql(
'create table if not exists account (id integer primary key not null, name text, balance int);',[],()=>console.log("creeeated"),(a,b)=>console.log(b)
);
console.log("created table account ");
tx.executeSql(
'create table if not exists transaction (id integer primary key not null, relatedAccount_id int, type int, amount int, balanceAfterTransaction int, dateTime text, description text, FOREIGN KEY(relatedAccount_id) REFERENCES account(id) );'
);
});
}
source = (name) =>{
console.log('hca');
console.log(name);
this.setState({ 'sourceName' : name});
}
addSource = ()=>{
console.log("entered addedSource");
db.transaction(
tx => {
console.log(tx.executeSql('insert into account (name , balance) values (?,0)',[this.state.sourceName],()=>console.log("sucess"),(a,b)=>console.log(b)));
console.log("inserted new account"+this.state.sourceName+"fin");
tx.executeSql('select * from account', [], (_, { rows }) =>
console.log(JSON.stringify(rows)),(a,b)=>console.log(b)
);
console.log("exit");
}
)
};
render() {
return (
<View style = {styles.container}>
<TextInput style = {styles.textInput} autoCapitalize = 'none' placeholder = 'sourceName'
onChangeText = { this.source}/>
<Button title="Add Source" onPress = {this.addSource}/>
</View>
)
}
}
export default AsyncStorageExample
const styles = StyleSheet.create ({
container: {
flex: 1,
alignItems: 'center',
marginTop: 50
},
textInput: {
margin: 15,
height: 35,
borderWidth: 1,
backgroundColor: '#7685ed'
}
})
When I try to insert data into account it shows error ( no such table: account (code 1)