开发者

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

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)

开发者_StackOverflow

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜