iOS使用SQLITE数据库。即使设置了限制,SQLITE_ROW也会返回100

时间:2014-05-30 23:36:03

标签: ios sqlite limit

使用SQLite数据库浏览器,我可以发送查询:

" SELECT纬度,经度FROM位置WHERE businessid = 1453 LIMIT 3;"

我得到三行数据。出于某种原因,在我的应用程序代码中,SQLITE_ROW值是100,通过将其分配给int和日志记录来确定。所以这会产生某种无限循环,应用程序会无限期冻结。我真的很想知道为什么这个代码适用于我的应用程序的其他区域,我在其他表中读取但不在此处。这是代码。

if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) 
{

    for (int i = 0; i < appDelegate.userList.count; i++) // for each location in the user list, add to surrounding data
    {
        RMLocationItem *temp = [appDelegate.userList objectAtIndex:i];
        NSString *sqlStatement1 = [[NSString alloc]init];
        sqlStatement1 = [NSString stringWithFormat:@"SELECT latitude, longitude FROM locations WHERE businessid = %d limit 5;", temp.businessId];
        const char *sqlStatement = [sqlStatement1  UTF8String];
        sqlite3_stmt *compiledStatement;
        if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK)
         {
            //sqlite3_bind_int(compiledStatement, 1, temp.businessId);
            //int sr = SQLITE_ROW;
            //NSString* myNewString = [NSString stringWithFormat:@"%d", sr];
            //NSLog(myNewString);
            while( sqlite3_step(compiledStatement) == SQLITE_ROW)
            {

                double latitude = (double) sqlite3_column_double(compiledStatement, 0);
                double longitude = (double) sqlite3_column_double(compiledStatement, 1);

                sqlite3_reset(compiledStatement);


                RMLocationItem *newLocation = [[RMLocationItem alloc]initWithName: temp.nameOfPlace distance:0 Id:temp.businessId longitude:longitude latitude:latitude address:NULL city:NULL];

                [appDelegate.surroundingRestaurants addObject:newLocation];

            }
        }
        else  NSAssert1(0, @"Error while inserting data. '%s'", sqlite3_errmsg(database));

        // Release the compiled statement from memory
        sqlite3_finalize(compiledStatement);

    }
    sqlite3_close(database);
编辑:解决了谢谢,就像@rmaddy说的那样,我拿了sqlite3_reset(compiledStatement); out和move完成直到while循环之后。

0 个答案:

没有答案