在国外的网站上找到一下类似的问题,加以修改了一下,希望有人可以帮帮忙,折腾了两天了.也不知道是什么问题
I have an app for iPhone who use the sqlite to read a database. Before I update my iOS from 4.3 to the latest one everything was fine. But since then, I notice a considerable loading of the data. I used the libsqlite3.0.dylib, which comes with the iOS sdk. I also found the source code (sqlite3.h and sqlite3.c) for version 3.7.6.3 but still have the same problem. So I traced the call of the sqlite3_step until I reached the this line:
for(pc=p->pc; rc==SQLITE_OK; pc++)
{}
in the method [b]sqlite3VdbeExec[/b], line [b]62789[/b] That for loop is the reason of the block. It remains there for few seconds, 3 - 6 seconds, but for the user interface this is lot of time. Even if I execute it on another thread it will still slow down the loading of the data which is not nice. Does anyone knows why and how this can be fixed? This is part of my code, where the method is called. Remember this block happen only at the first execution!
sqlite3* database;
NSString *databasePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"database.sqlite"];
NSString *sqlQuery = ...;
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK)
{
const char* sqlStatement = [sqlQuery UTF8String];
sqlite3_stmt* compiledStatement;
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK)
{
while(sqlite3_step(compiledStatement) == SQLITE_ROW)
{
... // process here, close the loop, close the db connection, etc...
But in the simulator will soon,
SQL statement has four conditions:
like this "where Categorys like '%;1036;%' and DistrictID=48 order by Ranking desc,OrderNo"
Categorys is string
DistrictID,ranking,orderNo is int
I tested several ways with the 4 conditions:
categorys,districtID,ranking the 3 conditions ,,, is slow, about 4s
categorys, districtID, orderNO about 1s
districtID, Ranking,orderNO also very slow,about 3.7s
districtID,ranking 2 conditions ,,, about 0.2s
districtID,orderNO about 0.2s
还是写出整条sql语句吧
select * from Shop where Categorys like '%;1036;%' and DistrictID=48 order by Ranking desc,OrderNo limit 0, 50
该sql语句,直接在终端里面查询的话,也是非常快的,在模拟器上速度也还正常的,不知道为什么一去到真机上就会异常的慢,整个数据库才12m左右,查询50条数据不应该那么慢才对的.
先谢谢各位大神啦!
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。