Reactive expo-sqlite is the problem.

Asked 2 years ago, Updated 2 years ago, 109 views

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

react-native sqlite

2022-09-20 22:29

1 Answers

    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.


2022-09-20 22:29

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.