I am attempting to insert rows into a SQLite DB. It takes 7 seconds to insert 130 rows, this seems slow to me.
Table definition is :
sd.execSQL("CREATE TABLE " + V2VocabsTable.TABLE_NAME + " ("
+ V2VocabsTable.ID + " VARCHAR(10) PRIMARY KEY ,"
+ V2VocabsTable.NAME + " VARCHAR(255), "
+ V2VocabsTable.LOADED + " VARCHAR(1) "
+ ");"
);
To insert a row I use the following code :
public void addTableStatus(String tableId, String name) {
Log.d("DB","Before Insert");
ContentValues cv = new ContentValues();
cv.put(V2VocabsTable.ID, "Table " + tableId);
cv.put(V2VocabsTable.NAME, name);
cv.put(V2VocabsTable.LOADED, "NO");
SQLiteDatabase sd = getWritableDatabase();
long result = sd.insert(V2VocabsTable.TABLE_NAME, null, cv);
Log.d("DB","After Insert :: " + result);
}
Times in the log file are :
12-17 23:00:11.445: D/SQLDB(25384): Init
12-17 23:00:11.455: D/DB(25384): Before Insert
12-17 23:00:11.505: D/SQLDB(25384): Open
12-17 23:00:11.895: D/DB(25384): After Insert :: 1
12-17 23:00:11.895: D/DB(25384): 0001 :: AdministrativeSex-v1.0.xml
12-17 23:00:11.895: D/DB(25384): Before Insert
12-17 23:00:11.965: D/DB(25384): After Insert :: 2
12-17 23:00:11.965: D/DB(25384): 0002 :: MaritalStatus-v1.0.xml
12-17 23:00:11.965: D/DB(25384): Before Insert
12-17 23:00:12.005: D/DB(25384): After Insert :: 3
12-17 23:00:12.005: D/DB(25384): 0004 :: PatientClass-v1.0.xml
12-17 23:00:12.005: D/DB(25384): Before Insert
12-17 23:00:12.145: D/DB(25384): After Insert :: 4
12-17 23:00:18.815: D/DB(25384): Before Insert
12-17 23:00:18.865: D/DB(25384): After Insert :: 131
12-17 23:00:18.865: D/DB(25384): ZU057 :: LocationHiding-v1.0.xml
12-17 23:00:18.865: D/DB(25384): Before Insert
12-17 23:00:18.925: D/DB(25384): After Insert :: 132
This seems excessively slow to me, what could be slowing it down?
The above code will will enable you to do transaction. In transcation mode you should be able to increase your speed up by a lot. And as comment pointed out, you start transaction then insert your x number of rows then close it.