1

I have a CSV file and am trying to convert it into an SQLite .db file so that I can use it in my Android app.

I am aware of methods I can use within the app to convert a CSV placed in the assets folder to an SQLite database within the Android app (e.g. by reading all lines from the CSV file and adding them to the SQLite database), however I want to generate a .db file outside of the app.

The reason I would prefer to do this is because I have several CSVs at around 5 MB each (over 350,000 rows) and so it would take too long to read them all and put them into a new SQLite database in the Android app.

I'm hoping that being able to put my .db files into the assets folder and using the android-sqlite-asset-helper library to access the data from these will be faster.

I have tried tools like a CSV to SQL converter which uses the data from the CSV file you upload to generate an SQL script (i.e. DROP then CREATE then INSERT), but I'm not sure what I need to do with the .sql file to make a .db out of it.

There are also some ways of doing this (I think) I found on Stack Overflow with commands, but I am unsure of how these work and how I use the commands.

So I am asking how I can convert a CSV file into an SQLite database. What is the best method?

Community
  • 1
  • 1
Farbod Salamat-Zadeh
  • 19,687
  • 20
  • 75
  • 125

1 Answers1

2

Out of curiosity, have you tried creating the database from within the SQLite CLI? Facilities for CSV import exist: https://www.sqlite.org/cli.html#section_8 followed up with a quick ".save output.db" may accomplish what you need.