Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create an SQLite database in Android by importing from an SQL file?

I have a big text file containing SQL CREATE TABLE and INSERT statements. How do I import this file in the SQLiteOpenHelper onCreate method?

Or, is there an accepted way of using the binary database file directly?

I need this to be compatible with Android 1.6.

like image 966
rid Avatar asked Jun 21 '11 23:06

rid


1 Answers

I had to solve the same problem. Couldn't find a direct way to do it, so I put the file into the res/raw directory and used openRawResource to get an InputStream on it. I then read lines until one ended with a ;. I then passed the statement to the sqlite database.

Hopefully someone else comes along with a better way, but I thought I would just add the way that I ended up doing it.

like image 167
Steve Prentice Avatar answered Nov 09 '22 03:11

Steve Prentice