I have an app with an SQLite database for storing information for a user's account. I designed the database on the assumption that the app would only have one user. As such, the user's ID isn't stored in the database (but it is stored in a central database on a server). However, it is possible to logout of the app and let another user log in, but the problem with this is at the moment, their data is downloaded and then appended to the other user's data. This is not what I want to happen, but I'm not sure how best to change the databse design to solve this. I have thought about:
Is one of these approaches good? Or is there a better way to do this?
Yes SQLite can support multiple users at once. It does however lock the whole database when writing, so if you have lots of concurrent writes it is not the database you want (usually the time the database is locked is a few milliseconds - so for most uses this does not matter).
SQLite supports an unlimited number of simultaneous readers, but it will only allow one writer at any instant in time. For many situations, this is not a problem. Writers queue up. Each application does its database work quickly and moves on, and no lock lasts for more than a few dozen milliseconds.
Maximum Database Size 140 tb but it will depends on your device disk size.
PostgreSQL. A unique relational database, PostgreSQL is the best database for Android and iOS apps. Developers can customize this database as they want; that's why it's the most preferred mobile app database.
I would go for option 1. Keeping it as a separate file will ensure that there won't be any performance implication whatsoever by having multiple databases.
You can append the user ID to the database filename. You could have some sort of LRU system where you automatically delete the oldest database if you have more than 4 (or if you exceed a certain amount of data).
The specifics of this choice would be up to you, since you know how much data storage you'd like to use up, and how many users would be likely to use the app on the same device.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With