0

块引用

我还使用表创建了数据库并将其存储到 android/app/src/main/assets/sqlite.db 并将 createFromLocation 设置为 1 或 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)
                    }, 
                )                   
            });
             
    }

4

1 回答 1

0

这对我有用

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)

  });
});

于 2021-06-05T14:37:53.407 回答