Is it possible to take the csv file stored in the res / raw resource directory and use it to populate the table in the sqlite3 database?
My thought was that if there was a way to mass import the entire file into a table, it would be cleaner and faster than repeating each line in the file and executing separate insert instructions ...
I found that there is a sqlite import command that allows this: How to import a .sql or .csv file into SQLite?
... but I'm having problems applying these statements in an Android app. My first thought was to try something like the following ... but no luck:
db.execSQL("CREATE TABLE " + TABLE_NAME + "(id INTEGER PRIMARY KEY, name TEXT)"); db.execSQL(".mode csv"); db.execSQL(".import res/raw/MyFile.csv " + TABLE_NAME);
Is it possible?
Should I try to use a different approach to populate my database?
UPDATE: I mark Joseph's answer as an answer (bulk insert using transactions), because it works great and directly answers my question based on my title (thanks Josef). However, I'm still looking for a way to do bulk insertion in an Android application from a csv file into a sqlite3 table using the import statement. If you know how to do this, answer.
Thanks for answers!
android database import sqlite sqlite3
MoMo May 22 '10 at 5:57 a.m. 2010-05-22 05:57
source share