Reputation: 51
I need for my project a SQLite database to store relevant information, which will be read next time, when I start the program.
Is it better to read the complete database, creating objects for each row and work on these objects stored in a list now or should I always ask the database for the row?
The database will have around 10,000 rows and get around one query each second, where I want to select a row. And if I should work with objects in a list, how can I bring them back? I think dropping the table and creating a new one is not the best solution.
Upvotes: 2
Views: 672
Reputation: 1757
Premature optimization is the root of all evil. -- Donald Knuth
You really shouldn't be optimizing something that isn't a performance problem right now.
Upvotes: 0
Reputation: 11783
There's up and downs to each option:
Get all from db into a list of objects:
Plus:
Minus:
Get each when you need it:
Plus:
Minus:
In each case, I doubt performance wise you'll notice a huge difference assuming your rows aren't huge.
If you do decide to query once and work with the objects, you'll have to either save all or save all the one that changed before you quit (and if your program dies unexpectedly, you might lose changes).
If you get one item at a time, and then save it, more calls to db (disk, since it's sqlite), but if something goes bad, you might lose less info.
Upvotes: 2