Creating an app with react native
You have installed expo-sqlite to use client db.
I created a db file, put it in the project directory, and entered a dummy record.
However, the callback function that displays the results is not executed. I don't know where the problem is.
import React, {Component} from 'react';
import {View} from 'react-native';
import * as SQLite from 'expo-sqlite'
class INPUT extends Component{
constructor(){
const db = SQLite.openDatabase('record.db');
db.transaction(
tx => {
tx.executeSql(
'select * from record',
[],
(trans, result) => {
console.log(result)
}
);
}
);
}
render(){
return(
<View>
</View>
)
}
}
export default INPUT
constructor(props){
super(props)
this.state={
}
db.transaction(tx => {
tx.executeSql(
'CREATE TABLE IF NOT EXISTS names (num INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, target TEXT, display INTEGER);'
);
})
}
You can solve it by using the keyword IF NOT EXISTS in this way in the constructor.
© 2024 OneMinuteCode. All rights reserved.