4

How does a CSV database compare to an SQLite database in Android?

Looking at other questions on StackOverflow, and reading Android Developer Documentation, I have seen SQLite databases being used far more often than reading data from a CSV file. There are also some questions where users have wanted to import a CSV file into an SQLite database (for example, this question or this one). Is there an advantage to using SQLite over CSV?

I have tried using both CSV and SQLite a little, and in terms of performance I don't see a huge difference, but correct me if I'm wrong here.
As I know there are different methods of reading a CSV file, I opened and read it using the BufferedReader like so:

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

And the SQLite database was opened in the usual way:

SQLiteDatabase db = helper.getReadableDatabase();

I'm not too sure about differences in functionality, although I am assuming SQLite is easier to manage and filter through, and that's why I'm asking this question.

So to summarise:

  • Are any of the two faster in terms of performance?
  • Does SQLite (or CSV) have any additional functionality that the other does not, especially in Android (as I am aware Android has its own SQLiteDatabase class?
  • Why does it seem that SQLite is used far more than CSV databases (i.e. reading and filtering a CSV file)?

EDIT:

Just to clarify, I know a CSV file is just a file with commas separating values, i.e. not a 'database' as a SQL database is. However I can still use a CSV file as a sort of database, where the comma separated values indicate different columns, which can also be filtered, by checking to see if a particular column matches a particular value. So I am asking which is better to read data from.

Community
  • 1
  • 1
Farbod Salamat-Zadeh
  • 19,687
  • 20
  • 75
  • 125
  • A CSV file is NOT a database. It's just a list of records in a plain text file. Those records aren't searchable and you can't aggregate or sort them. And if you want to manipulate (i.e.: UPDATE) a row, it's a real PAIN. – Phantômaxx Sep 13 '15 at 17:59
  • @FrankN.Stein True, but I can still use a CSV file as a sort of database, where the comma separated values indicate different columns, which can also be filtered, by checking to see if a particular column matches a particular value. – Farbod Salamat-Zadeh Sep 15 '15 at 15:20
  • 2
    Filtered... only if you read the file line by line, which is not efficient at all. Let's say a CSV is more a temporary backup for a single table. – Phantômaxx Sep 15 '15 at 16:50

1 Answers1

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.

selfthinker
  • 554
  • 1
  • 5
  • 15
Bert Peters
  • 1,505
  • 13
  • 30