Unable to execute any query in SQLite with react-native-sqlite-storage ...i am trying it for android tv app

260 views Asked by At

Blockquote

I also created database with table and store it into android/app/src/main/assets/sqlite.db and also set createFromLocation to 1 or 2

    useEffect(() => {
        try {
            db = SQLite.openDatabase({
                name: "sqlite.db",
                createFromLocation:"~sqlite.db"

            },
                sucessToOpen,
                errorToOpen
            )
        }
        catch (err) {
        console.log(err)
        }
    }, [])
    
    ....
    const sucessToOpen = async (data) => {
    
        console.log("DB connected",data)
            db.transaction(tx => {
                tx.executeSql(
                    'SELECT * FROM hydro',[],
                    (tx, results) => {

                        let datalength = results.row.length
                        alert(datalength)
                        console.log("results",datalength)
                    }, 
                )                   
            });
             
    }

1

There are 1 answers

1
Sumit Sharma On BEST ANSWER

This work for me

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

  });
});