Search code examples
iosobjective-csqlitefmdb

FMDB Multiple Record Update Query


Is this possible and how would one go about it if it is? Info on the topic is a bit sparse given a Google & Stack search, lots on batch inserts, but nothing solid on batch updates.


Solution

  • Yes it is possible if you insert the correct SQL to do it, but your question is a bit vague.

    Rather than trying to update multiple records in a query though, why don't you use a transaction queue instead? Pass your queries in as an array to this function. (requires you have setup an FMDatabase dbQueue of course)

    -(BOOL) executeQueryArray:(NSMutableArray*)queryArray {
    
        __block BOOL noErrors = YES;
    
        [self.dbQueue inTransaction:^(FMDatabase *db, BOOL *rollback) {
    
           db.logsErrors = YES;
    
            for (NSString* query in queryArray) {
    
                if (![db executeUpdate:query]) noErrors = NO;
            }
    
            *rollback = !noErrors;
        }];
        return noErrors;    
    }