Should I use a flat file or database for storing quotes for a random quotations app on Android?

StackOverflow https://stackoverflow.com/questions/1565869

문제

I am developing an app on Android that will randomly pick and display an inspirational quotation (or verse) from a large collection of quotations. On Android I can choose between a flat file and an SQLite database.

The app should satisfy the following conditions:

  1. Be scalable to 10^6 quotations and/or verses

  2. Be very fast (i.e. retrieve and display a quotation, immediately at the touch of a button)

  3. Be able to load new quotations from an external source (in a format I have not yet decided)

What data format must I use? Thanks.

도움이 되었습니까?

해결책

I'd go with a very simple database, single table:

Quotes
ID          sequential integer PK
Quote       text/string

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

The problem with a flat file is quickly finding and reading a quote from the middle of the file. This is what a database does well. Also with a "flat" file you'll have a lot of wasted space at the end of file lines.

Also, if you can load new quotes, why populate 10^6 at any one time? just load enough to keep the app going and march through them in a sequential order, deleting viewed ones and loading new ones. This approach would require you to keep track of the last loaded quote, so you are always loading new ones.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top