我同时对review_schedule表执行更新和插入操作。似乎两者的时间都在1到2秒之间,这有点慢。我尝试过在id字段和date_review字段上分别设置和不设置索引。请注意,我使用的是insert的预编译语句,而不是update语句,因为Gingerbread显然不支持update的编译语句。代码如下:
public long insert(int id, String lastReviewDate, String nextReviewDate) {
this.insertStmt.bindLong(1, id);
this.insertStmt.bindString(2, lastReviewDate);
this.insertStmt.bindString(3, nextReviewDate);
return this.insertStmt.executeInsert();
}
public void updateSRSInfo(int id, String lastReviewDate,
String nextReviewDate) {
ContentValues contentValues = new ContentValues();
contentValues.put("last_review_date", lastReviewDate);
contentValues.put("next_review_date", nextReviewDate);
this.myDataBase.update(DataBaseHelper.WORD_REVIEW_SCHEDULE,
contentValues, "_id=?", new String[] { Integer.toString(id) });
}如有任何建议,欢迎光临。
发布于 2011-07-29 07:13:07
如果过程的长度使应用程序没有响应,也许你可以将操作移到不同的线程中。
发布于 2011-07-22 14:20:12
至少有两个选项:
1)读取未提交的事务,因为默认情况下SQLite只读取已提交的事务,这很慢。但你必须了解你所面临的所有reading uncommitted records风险。可以通过以下方式更改事务隔离级别:
database.execSQL("PRAGMA read_uncommitted = true;"); 2)使用表格索引
发布于 2011-07-22 17:47:58
既然你已经有了一个id,为什么不把它和ContentUri.withAppendedId结合起来,这样你就可以直接访问这个记录了。我不确定这是否运行得更快,因为我还没有测试过它。
https://stackoverflow.com/questions/6784286
复制相似问题