您的位置:首页 > 数据库

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);

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: