- expo-cli 4.0.17
expo-sqlite 8.5.0
react-native sdk-40.0.1 - Android/web
Hi.
The “with-sqlite” example works fine on Android Expo app. However, web version fails when it tries to access sqlite query results.
First exception is TypeError: Cannot read property 'length' of undefined
. But it is not the actual source of issue, just a side effect of undefined variable.
Actually, the issue is in the query result. According to docs (and code applies this knowing) the result is represented as
{
insertId,
rowsAffected,
rows: {
length,
item(),
_array,
},
}
The _array
field then used to be set as items
state
React.useEffect(() => {
db.transaction(tx => {
tx.executeSql(
`select * from items where done = ?;`,
[doneHeading ? 1 : 0],
(_, { rows: { _array } }) => setItems(_array)
);
});
}, []);
Web version works sligltly differently. The result does not have rows._array
property. Instead, rows property represent SQLResultSetRowList
object which provides item(i)
method to access the actual resultset rows.
Fix in form below works for me.
let res_array = [];
for (let i=0; i<result.rows.length; i++){
res_array.push(result.rows.item(i));
}
setItems(res_array);
My question is - why this differs in Web and Android version? Where it should be fixed? If it is possible to fix, of course.
Thanks.