Inserted data not showing in table when selected

Hi all, would appreciate a hand.

I’m attempting to create a database where I can store tokens for an app of mine.

Initially, a user logs in and a token is set.

login = (login_token, navigator) => {
        //Store login token
        this.storeToken(login_token).then(token => {
            if (token != null) {
                this.token = token;
                this.changePage("SelectTour", navigator);
                return true;
            }
            else {
                console.log("Token is undefined or null in login()")
            }
        });
    };

Storing token:

    storeToken = (login_token) => new Promise((resolve, reject) => {
        this.createMoneyTables.then((status => {
            console.log("Created tables: " + status);
            if (status) {
                this.deleteToken.then((status => {
                    console.log("Deleted token: " + status);
                    config.db.transaction(tx => {
                        console.log("Storing: " + login_token);
                        tx.executeSql('insert into tokens (token) values ("' + login_token + '")');
                        tx.executeSql(
                            `select * from tokens`,
                            [],
                            (_, { rows: { _array } }) => {
                                resolve(_array[0].token)
                            }
                        );
                    });
                }));
            }
        }));
    });

Once the token is set, the token should be stored in the database - and the resolve(_array[0].token) shows that the token is there. So the insert has been completed correctly.

Then, when changing the page to another component, get tokens should retrieve the token and resolve() it, but instead returns nothing - . This indicates that it hasn’t been saved?

    getLoginTokens = new Promise((resolve, reject) => {
            config.db.transaction(tx => {
                tx.executeSql(
                    `select * from tokens`,
                    [],
                    (_, { rows: { _array } }) => {
                        resolve(_array[0].token)
                    }
                );
            });
    });

Am i performing the database query correctly? Is there a way i should be committing the transaction to ensure it saves?

P.S. reason for so many promises is i was testing to see if something else was at fault. This wasn’t the case.

Another thing to note, when restarting the Expo app, the data retrieves from the database. Only in the existing instance it does not retrieve the data.

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.