1

当为相同的“DBName”值调用以下函数时,将返回不同的布尔值。我期待找到一个副本。第一次尝试它有效,第二次尝试它没有。我做错什么了吗?

-(BOOL)CheckForDB:(NSString *)dbPath{
if (sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK) {
    if(checkForDB == nil){

        const char *sql = "SELECT  COUNT(*) FROM BookingInfo WHERE DBName = ?";
        if(sqlite3_prepare_v2(database, sql, -1, &checkForDB, NULL) != SQLITE_OK) {
            NSAssert1(0, @"Error while fetching uploaded status. '%s'", sqlite3_errmsg(database));
        }
    }

    sqlite3_bind_text(checkForDB, 1, [dbName UTF8String], -1, SQLITE_TRANSIENT);

             NSLog(@"checking status %@",dbName);
    while(sqlite3_step(checkForDB) == SQLITE_ROW) {



        NSString *status=[NSString stringWithUTF8String:(char *)sqlite3_column_text(checkForDB, 0)];
        return [status boolValue];
    }

    return NO;
    sqlite3_reset(checkForDB);


}else{
    sqlite3_close(database);
  }
}
4

1 回答 1

1

我找到了解决方案。在我调用 return YES 之前,我必须再调用一次 sqlite3_reset(checkForDB)

while(sqlite3_step(checkForDB) == SQLITE_ROW) {



    NSString *status=[NSString stringWithUTF8String:(char *)sqlite3_column_text(checkForDB, 0)];
    sqlite3_reset(checkForDB)
    return [status boolValue];
}
于 2013-04-10T07:34:55.373 回答