I am new to react native, I am trying to connect with sqlite but when doing the transaction I get the following error, I have put some console.log, but it cannot enter after the transaction.
import { useEffect, useState } from "react";
import { Text, View } from "react-native";
import SQLite from "react-native-sqlite-storage";
export default function ListProducts(props: unknown) {
const [names, setNames] = useState<string[]>([]);
useEffect(() => {
const initializeDatabase = async () => {
try {
const db = SQLite.openDatabase({
name: "mydata",
createFromLocation: 1
});
console.log('asdasd');
db.transaction(tx => {
console.log('transaction');
tx.executeSql('CREATE TABLE IF NOT EXISTS products (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)');
});
} catch (error) {
}
};
initializeDatabase();
}, []);
return (
<View>
{names.map((name, index) => (
<Text key={index}>{name}</Text>
))}
</View>
);
}
I hope I can execute the transaction well and make queries to sqlite
New contributor
Oscar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.