Should I use a flat file or database to store quotes for a random quotes app on Android?

I am developing an Android application that will randomly select and display an inspirational quote (or verse) from a large collection of quotes. On Android, I can choose between a flat file and a SQLite database.

The application must meet the following conditions:

  • Scalable to 10 ^ 6 quotes and / or verses

  • Be very fast (i.e., extract and show the quote immediately with the click of a button)

  • Be able to download new quotes from an external source (in a format that I haven't decided yet)

What data format should I use? Thank.

+2


source to share


1 answer


I would use a very simple database, one table:

Quotes
ID          sequential integer PK
Quote       text/string

      

with a possible "Viewed" field that you can update to prevent duplicates. Generate a random value and select that row from the table, mark it scanned and do with it.



The flat file problem quickly finds and reads the quote from the middle of the file. This is what the database does. Also with a "flat" file, you will have a lot of wasted space at the end of the lines in the file.

Also, if you can download new quotes, why fill 10 ^ 6 at any moment? just download enough for the app to keep going and going through them in sequential order, deleting viewed ones and loading new ones. This approach will require you to keep track of the last quote downloaded, so you always download new ones.

+3


source







All Articles