4

CSV データベースは Android の SQLite データベースと比べてどうですか?

StackOverflow に関する他の質問を見て、Android 開発者向けドキュメントを読んで、SQLite データベースが CSV ファイルからデータを読み取るよりもはるかに頻繁に使用されているのを見てきました。また、ユーザーが CSV ファイルを SQLite データベースにインポートしたいという質問もいくつかあります (たとえば、この質問またはこの質問)。CSV よりも SQLite を使用する利点はありますか?

CSV と SQLite の両方を少し使用してみましたが、パフォーマンスに関しては大きな違いは見られませんが、ここで間違っている場合は修正してください。
CSVファイルを読み取るにはさまざまな方法があることを知っているBufferedReaderので、次のように開いて読み取りました。

BufferedReader reader = 
        new BufferedReader(new InputStreamReader(context.getAssets().open(fileName)));

そして、SQLite データベースは通常の方法で開かれました。

SQLiteDatabase db = helper.getReadableDatabase();

機能の違いについてはよくわかりませんが、SQLite の方が管理とフィルター処理が簡単であると想定しているため、この質問をしています。

要約すると:

  • パフォーマンスの点で 2 つのどちらかが高速ですか?
  • SQLite(またはCSV)には、特にAndroidでは、他の機能にはない追加機能があります(Androidには独自のSQLiteDatabaseクラスがあることを知っているので?
  • SQLite が CSV データベース (つまり、CSV ファイルの読み取りとフィルタリング) よりもはるかに多く使用されているように見えるのはなぜですか?

編集:

明確にするために、CSVファイルは値をコンマで区切った単なるファイルであり、SQLデータベースのような「データベース」ではないことを知っています。ただし、特定の列が特定の値と一致するかどうかを確認することで、CSV ファイルを一種のデータベースとして使用することもできます。カンマ区切りの値は異なる列を示し、フィルター処理することもできます。そこで、どちらからデータを読み取るのが良いかを尋ねています。

4

1 に答える 1

3

SQLite and CSV are not really the same thing, which makes the comparison rather difficult. SQLite is a (limited) SQL database, which means that you can use it to store structured and related data in a way that ensures consistency (related records not messing up when either is deleted) and simple way.

Even for flat data, SQLite makes it easier to query a subset of your data (say, all records where one of the columns is less than three), reorder the data depending on your needs and insert a record somewhere in the middle.

CSV on the other hand, is just a text file, that you can use for very simple data. It has little overhead, but it won't help you very much in the sense of data integrity and easy querying. If you don't need this, and always read all of it, sure, you can use CSV.

If none of this rings any bells to you (related records, and data integrity and such) I suggest reading up on relational database systems. As always, Wikipedia is an excellent source.

于 2015-09-13T17:42:51.007 に答える