I'm new to React Native Expo and I'm trying to use SQLite for storing data locally in my app. I followed a tutorial and managed to set up the database using the expo-sqlite package. Everything seems to be working fine, but when I try to check the data in the SQLite database file using DB Browser for SQLite, I can't see any of the data I've inserted.
Here's a simplified version of my code:
async function insertData(data_to_submit) {
try {
const result = db.runAsync(
`INSERT INTO BizUser (
WhiteLabelURL, BizUser, BizUserPassword, BizUserName, BizUserEmail,
BizUserCell, BizUserAddress, BizUserClass, BizLocationLatitude,
BizLocationLongitude, BizLocationDescription, BizFeaturedImage,
ActiveStatus, ActiveStatusDateTime, SignupDateTime, BizLastUpdate,
BizLastUpdateDateTime
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);`,
[
data_to_submit.WhiteLabelURL,
data_to_submit.BizUser,
data_to_submit.BizUserPassword,
data_to_submit.BizUserName,
data_to_submit.BizUserEmail,
data_to_submit.BizUserCell,
data_to_submit.BizUserAddress,
data_to_submit.BizUserClass,
data_to_submit.BizLocationLatitude,
data_to_submit.BizLocationLongitude,
data_to_submit.BizLocationDescription,
data_to_submit.BizFeaturedImage,
data_to_submit.ActiveStatus,
data_to_submit.ActiveStatusDateTime,
data_to_submit.SignupDateTime,
data_to_submit.BizLastUpdate,
data_to_submit.BizLastUpdateDateTime,
]
);
const allUsers = await db.getAllAsync("SELECT * FROM BizUser");
console.log("Data inserted successfully", result);
} catch (error) {
console.error("Error inserting data:", error);
}
}
Even though the console logs show that the data is being inserted and retrieved successfully, I can't see anything when I open the mydb.db file in DB Browser for SQLite.
Can someone please help me understand why the data isn't showing up in the database file? Am I missing a step or misunderstanding something about how SQLite works with React Native Expo?
Any advice or explanations would be really helpful. Thanks a lot!
I just had this same issue and realized that expo-sqlite is creating a new local database based on the database file you provide. It doesn't actually update or write to the original source file it just uses it as a seed to create a new database.
Hope that helps.