I'm inserting rows in android SQLite database from a file. In the onUpdate function in the databaseHelper I call the insertInDb function:
InputStream is = null;
AssetManager assetManager = context.getResources().getAssets();
String fileLine = "";
String[] data;
ContentValues row = new ContentValues();
long rowid;
try {
is = assetManager.open(filename);
BufferedReader br = new BufferedReader(new InputStreamReader(is));
db.beginTransaction();
while((fileLine = br.readLine()) != null){
data = fileLine.split("@-@");
row.put(QuoteAllEntry.COLUMN_QUOTE, data[0]);
row.put(QuoteAllEntry.COLUMN_AUTHOR, data[1]);
row.put(QuoteAllEntry.COLUMN_FAVORITE, 0);
row.put(QuoteAllEntry.COLUMN_CAT_KEY, data[2]));
rowid = db.insert(DataContract.QuoteAllEntry.TABLE_NAME, null, row);
}
db.setTransactionSuccessful();
}catch (Exception e) {
e.printStackTrace();
}
finally {
db.endTransaction();
}
Only one row of data is inserted, and it is the last row of the file. What is going wrong? I can't seem to find the problem.