I had problem with multiple insert in sqlite
database when my table has been growing up.
with 200 insert in table I've face to freezing UI even I've wrote my insert query in back thread. ( might be synchronized method cause this , database is busy and reading must be lock until inserting has been finished)
I see This Link that is very helpful to understand many option that i can customize in database. but i can't use any one of those except SYNCHRONIZE.
I've think to use Prepared Statement but as i use content provider and i see source code, content provider use that in default.
following code is from source:
public long insertWithOnConflict(String table, String nullColumnHack,
ContentValues initialValues, int conflictAlgorithm) {
acquireReference();
try {
StringBuilder sql = new StringBuilder();
sql.append("INSERT");
sql.append(CONFLICT_VALUES[conflictAlgorithm]);
sql.append(" INTO ");
sql.append(table);
sql.append('(');
Object[] bindArgs = null;
int size = (initialValues != null && initialValues.size() > 0)
? initialValues.size() : 0;
if (size > 0) {
bindArgs = new Object[size];
int i = 0;
for (String colName : initialValues.keySet()) {
sql.append((i > 0) ? "," : "");
sql.append(colName);
bindArgs[i++] = initialValues.get(colName);
}
sql.append(')');
sql.append(" VALUES (");
for (i = 0; i < size; i++) {
sql.append((i > 0) ? ",?" : "?");
}
} else {
sql.append(nullColumnHack + ") VALUES (NULL");
}
sql.append(')');
SQLiteStatement statement = new SQLiteStatement(this, sql.toString(), bindArgs);
try {
return statement.executeInsert();
} finally {
statement.close();
}
} finally {
releaseReference();
}
}
tell me if it's not right.
i can't use Transaction
in this case because i don't know when incoming messages has been end. and i can't wait or inserting with delay, to get next message
i can't use journal_mode = MEMORY
either because it's risky.
is there any solution to optimize insert ? my code is not important, it's simple insert but in big table. ( in column number and row number ) if you want to see my code tell me, i will post that