【发布时间】:2017-06-24 09:49:22
【问题描述】:
我正在使用以下代码从 SQlite 获取数据,我很快就在光标中获得了完美的数据。
当我迭代游标时,从游标中获取 31 条记录需要 >10 秒。
我的查询需要 0.016150 秒来执行。
我怎样才能将这个时间减少到
Cursor cursor = dbHelper.getFollowedValuesForCalendar();
if(cursor!=null && cursor.getCount()>0)
{
cursor.moveToFirst();
int followedDateIndex = cursor.getColumnIndex(Info.FOLLOWED_DATE);
int followedCountIndex = cursor.getColumnIndex(Info.FOLLOWED_COUNT);
int successValueIndex = cursor.getColumnIndex(Info.SUCCESS_VALUE);
int isEnableIndex = cursor.getColumnIndex(Info.IS_ENABLE);
do
{
Info.previousFollowedDaysList.add(cursor.getString(followedDateIndex));
Info.previousFollowedValuesList.add(cursor.getInt(followedCountIndex));
Info.successValuesList.add(cursor.getInt(successValueIndex));
Info.isEnableList.add(cursor.getInt(isEnableIndex));
}while(cursor.moveToNext());
}
else
{
//System.out.println(" Records between dates ==============>>>> 0");
}
if(cursor!=null)
cursor.close();
【问题讨论】:
-
你应该先优化 SQL 查询
-
您好 Paresh 感谢您的回复...我的查询需要 0.016150 秒的时间来执行。
-
@ParmarS :不完全是。 query 方法返回很快,因为它只计算查询的一部分,而其余部分在游标操作期间完成。请发布您的查询和您的数据库创建查询。