Search code examples
iossqlobjective-cnsmutablearrayfmdb

iOS: FMDB questions adding a lot of data to an array


I am getting a lot of data from the database. This is an example on what I am doing.

NSMutableArray *array = [[NSMutableArray alloc] init];

FMResultSet *s = [db executeQuery:@"SELECT * FROM myTable"];
while ([s next]) {
     NSString *idNumber = [result stringForColumn:@"id"];
     [array addObject:idNumber];
}

However, there is one issue that is making me nervous. What if I need to grab a lot of data from the database? Will this cause any memory issue or major slow downs? If so, what will be the best way to make sure this issue doesn't occur.


Solution

    1. Try to use query with filters WHERE
    2. Use background thread
    3. You're using only id field, so there's no need to grab all other fields: use SELECT id FROM myTable instead