SQLite Forum

Timeline
Login

2 forum posts by user 001533

2020-06-03
21:16 Post: Problem with select from Sqlite Expo. I can't save the array returned by the query through the hook function (artifact: 0da4384a4c user: 001533)

import React, {useState} from 'react'; import {DatabaseConnection} from '../database/conex'; import {DatabaseInit} from '../database/dbinit'; import { FlatList, Text, View } from 'react-native';

var db = null;

export default function viewAllUser(){

db = DatabaseConnection.getConnection();
const [users, setUsers] = useState([]);

db.transaction(tx => {
    tx.executeSql('SELECT * FROM user', [], (tx, results) => {
      var temp = [];
      for (let i = 0; i < results.rows.length; ++i) {
        temp.push(results.rows.item(i));                               
      }             
      {() => setUsers(temp)}
    });  

  });
 console.log(users);

}

21:08 Post: Expo Problem with Select * in ReactNative. I can’t save the returned query value (artifact: 45b44a46c5 user: 001533)

export default function ViewAllUser(){

db = DatabaseConnection.getConnection();

var listUsers = ;

db.transaction(tx => {

tx.executeSql('SELECT * FROM user', [], (tx, results) => {

var temp = [];

for (let i = 0; i < results.rows.length; ++i) {

temp.push(results.rows.item(i));                               

}

listUsers = temp;

});
});

console.log(listUsers);

} export default function ViewAllUser(){

db = DatabaseConnection.getConnection();

var listUsers = ;

db.transaction(tx => {

tx.executeSql('SELECT * FROM user', [], (tx, results) => {

var temp = [];

for (let i = 0; i < results.rows.length; ++i) {

temp.push(results.rows.item(i));                               

}

listUsers = temp;

});
});

console.log(listUsers);

}

Console.log returns an empty array :confused: