Reputation: 8312
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?
Upvotes: 14
Views: 3269
Reputation: 10193
That is really dependant on your requirements, however the 3rd option doesn't seem very practical. If you wnated to do this then it's the same as uninstalling and reinstalling your app.
I would probably be more inclined to use option 2 but it depends on what you want to do within your database. e.g. if you want statistics or queries across all users rather than an individual and if there is common data that is shared between users.
If you are worried storage size then write a service that purges data belonging to any user that hasn't logged in with a certain time frame.
Upvotes: 1
Reputation: 77732
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.
Upvotes: 4