Fetching complex data using FMDB
What I can suggest is:
Refine your SQL statement. Instead of 2 loops, you can simply change your statement into "
SELECT * FROM OffreMarket WHERE codeOffer IN (SELECT code FROM Offer)
". If you want to use column "name
" in table "Offer
", you can join two tables "codeOffer
" and "Offer
". The rule of thumb here is to avoid too many loops but try to combine or refine your SQL statement.Create index for column "
code
" in table "Offer
". It will speed up your searching a lot. For example, once in one of my project, I had to work on a SQL table with 36K records. With a simple index set to the primary key column, I managed to reduce the searching time on that table by 10 seconds.
In this case you can get the results with just one query:
select * from Offerleft outer join OffreMarket OM on (OM.codeOffer = Offer.code)
If you are using FMDB as a wrapper than here is your answer:
@try { // Select Contact Details From Modules NSString *selectSQL = [NSString stringWithFormat: @"SELECT * FROM %@ INNER JOIN %@ ON %@.%@=%@.%@ ;", OffreMarket, Offer, OffreMarket code Offer code]; //NSLog*(@"Get All Offers select SQL: %@", selectSQL); FMResultSet *resultSet = [db executeQuery:selectSQL]; NSMutableArray *marketOffers = [[NSMutableArray alloc]init]; while ([resultSet next]) { // Create Offers Details Modal Offer *offer = [[Offer alloc] init]; offer.code = [resultSet stringForKey:@"code"]; offer.name = [resultSet stringForKey:@"name"]; [marketOffers addObject: offer]; } return (NSArray *)infos;}@catch (NSException *exception) { //NSLog*(@"%@ : %@",exception.name,exception.reason); return nil;}return nil;
Try above Code..it will get you all the data in minimum time. FMDB is nice choice for database operation.