sqlite数据库多条记录操作效率问题

前端之家收集整理的这篇文章主要介绍了sqlite数据库多条记录操作效率问题前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

sqlite数据库更新500条数据花了43秒,汗一个

public void addIndexs(List<SearchIndex> newIndexs) {
if (newIndexs == null || newIndexs.size() == 0)
return;
sqliteDatabase database = sqliteDatabase.openDatabase(dbPath,PWD,null,sqliteDatabase.OPEN_READWRITE);
//sqliteDatabase database = sqliteDatabase.openDatabase(dbPath,sqliteDatabase.OPEN_READWRITE);

String insertsql = "INSERT INTO SearchIndex VALUES (?,?,?)";

String deletesql = "delete from SearchIndex where (StaffID=? or StaffID=?)";

database.beginTransaction();

SearchIndex tempIndex = null;
for (int i = 0; i < newIndexs.size(); i++) {
tempIndex = newIndexs.get(i);

database.execsql(
deletesql,
new String[] { tempIndex.S.toUpperCase(),
tempIndex.S.toLowerCase() });

database.execsql(insertsql,new String[] { tempIndex.S,
tempIndex.N,tempIndex.J,tempIndex.P,tempIndex.L,
tempIndex.E});
}

database.setTransactionSuccessful();
database.endTransaction();

database.close();
}

每次的execsql操作都是对数据库的一次事务

加上红色代码后,耗时变成了2秒



原文链接:https://www.f2er.com/sqlite/198801.html

猜你在找的Sqlite相关文章