i have \"food_db.sql\" file stored in /res/raw folder, it has tons of \'insert\' in it.
my question is how to i exec the file and get the data into sqlite databse in
@Override
public void onCreate(SQLiteDatabase db) {
InputStream is = null;
try {
is = context.getResources().openRawResource(R.raw.database_init);
String initSql = IOUtils.toString(is);
db.execSQL(initSql);
} catch (IOException e) {
Log.e(TAG, "Error loading init SQL from raw", e);
} catch (SQLException e) {
Log.e(TAG, "Error executing init SQL", e);
} finally {
IOUtils.closeQuietly(is);
}
}
An important callout is, SQLiteDatabase.execSQL(String sql) only execute a single SQL statement, multiple statements separated by semicolons are not supported.
I've tried a hard time to find out why my database_init.sql doesn't work as expected.