sqlite数据查询速度慢的可能原因
2015-04-13 15:12
381 查看
1.返回数据库字段信息与要查询数据库的数据字段不一致:
如下例:返回的字段少个IMGURL
String where = String::format("%s='%s'", AppBean::APPID().string(), appid.string());
DbResolver* p = DbResolver::getInstance();
if (p != NULL) {
StringArray pro(2);
pro.replaceAt(AppBean::PACKAGENAME(), 0);
pro.replaceAt(AppBean::APPNAME(), 1);
AutoCursor cursor = p->query(AppBean::DOWNLOAD_TABLE_NAME(), pro, where, StringArray(0), "");
if (cursor->moveToFirst()) {
String pkg = cursor->getString(cursor->getColumnIndex(AppBean::PACKAGENAME()));
String appname = cursor->getString(cursor->getColumnIndex(AppBean::APPNAME()));
String imageUrl = cursor->getString(cursor->getColumnIndex(AppBean::IMGURL()));
Demand d = NotificationDelegate::createDemand(appname, pkg, imageUrl, "", NotificationDelegate::STATUS_WAITDOWNLOAD, NotificationDelegate::PARAM_CANCEL);
mpContext->invokeDelegate(&d);
}
}
正确方式应为:
String where = String::format("%s='%s'", AppBean::APPID().string(), appid.string());
DbResolver* p = DbResolver::getInstance();
if (p != NULL) {
StringArray pro(3);
pro.replaceAt(AppBean::PACKAGENAME(), 0);
pro.replaceAt(AppBean::APPNAME(), 1);
pro.replaceAt(AppBean::IMGURL(), 2);
AutoCursor cursor = p->query(AppBean::DOWNLOAD_TABLE_NAME(), pro, where, StringArray(0), "");
if (cursor->moveToFirst()) {
String pkg = cursor->getString(cursor->getColumnIndex(AppBean::PACKAGENAME()));
String appname = cursor->getString(cursor->getColumnIndex(AppBean::APPNAME()));
String imageUrl = cursor->getString(cursor->getColumnIndex(AppBean::IMGURL()));
Demand d = NotificationDelegate::createDemand(appname, pkg, imageUrl, "", NotificationDelegate::STATUS_WAITDOWNLOAD, NotificationDelegate::PARAM_CANCEL);
mpContext->invokeDelegate(&d);
}
}
如下例:返回的字段少个IMGURL
String where = String::format("%s='%s'", AppBean::APPID().string(), appid.string());
DbResolver* p = DbResolver::getInstance();
if (p != NULL) {
StringArray pro(2);
pro.replaceAt(AppBean::PACKAGENAME(), 0);
pro.replaceAt(AppBean::APPNAME(), 1);
AutoCursor cursor = p->query(AppBean::DOWNLOAD_TABLE_NAME(), pro, where, StringArray(0), "");
if (cursor->moveToFirst()) {
String pkg = cursor->getString(cursor->getColumnIndex(AppBean::PACKAGENAME()));
String appname = cursor->getString(cursor->getColumnIndex(AppBean::APPNAME()));
String imageUrl = cursor->getString(cursor->getColumnIndex(AppBean::IMGURL()));
Demand d = NotificationDelegate::createDemand(appname, pkg, imageUrl, "", NotificationDelegate::STATUS_WAITDOWNLOAD, NotificationDelegate::PARAM_CANCEL);
mpContext->invokeDelegate(&d);
}
}
正确方式应为:
String where = String::format("%s='%s'", AppBean::APPID().string(), appid.string());
DbResolver* p = DbResolver::getInstance();
if (p != NULL) {
StringArray pro(3);
pro.replaceAt(AppBean::PACKAGENAME(), 0);
pro.replaceAt(AppBean::APPNAME(), 1);
pro.replaceAt(AppBean::IMGURL(), 2);
AutoCursor cursor = p->query(AppBean::DOWNLOAD_TABLE_NAME(), pro, where, StringArray(0), "");
if (cursor->moveToFirst()) {
String pkg = cursor->getString(cursor->getColumnIndex(AppBean::PACKAGENAME()));
String appname = cursor->getString(cursor->getColumnIndex(AppBean::APPNAME()));
String imageUrl = cursor->getString(cursor->getColumnIndex(AppBean::IMGURL()));
Demand d = NotificationDelegate::createDemand(appname, pkg, imageUrl, "", NotificationDelegate::STATUS_WAITDOWNLOAD, NotificationDelegate::PARAM_CANCEL);
mpContext->invokeDelegate(&d);
}
}
相关文章推荐
- SQLite查询优化,提高获取数据速度
- 添加索引后新数据查询速度慢,老数据速度快什么原因? ...
- SQL Server 百万级数据提高查询速度的方法
- 处理千万级以上的数据提高查询速度的方法(转)
- java使用JDBC连接数据库,提高查询大量数据速度
- SQL Server数据库查询速度慢原因及优化方法
- 处理百万级以上的数据提高查询速度的方法
- 关于mysql处理百万级以上的数据时如何提高其查询速度的方法
- sqlite3查询数据库数据
- MS SQL Server查询优化方法 查询速度慢的原因很多,常见如下几种
- 提升SQLite数据插入效率低、速度慢的方法
- 数据库SQLite 数据大量存储 和快速读取 链表查询的优化 使用gosn
- 同一个表中查询不同的数据,执行时间相差很远,是什么原因?
- 查询速度慢的原因很多,常见如下几种
- IOS开发数据库篇—SQLite模糊查询
- C#sqlite事务循环高效插入数据,天下文章一大抄,本例亲自测试过,速度嘎嘎的。
- ADODB数据分页查询提高数据显示速度
- dede数据库文件导入失败的可能原因是数据表前缀不同,这里的失败指的是mysql添加了数据,但后台不显示
- sqlite实用技巧:查询表数据时,使用列对齐,显示表头
- sql处理百万级以上的数据提高查询速度的方法