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.
Asked
Active
Viewed 750 times
0
-
1what u want to do exactly ? – Hitarth Mar 10 '16 at 07:22
-
see this http://stackoverflow.com/questions/11563869/update-multiple-rows-with-different-values-in-a-single-sql-query – Anbu.Karthik Mar 10 '16 at 07:26
-
you can refere that ans and another solution is that you can do it in for loop. so in single query. so Make one general query and use it in for loop. So you don't have to write query to update each record. – Hitarth Mar 10 '16 at 07:50
-
It seems weird to me that the proposed solution works in SQLite given there is not a q about it on here (at least not with any answers I could find) – ChuckKelly Mar 10 '16 at 10:48
-
Why is this being downvoted when no one has a answer or can show a example? – ChuckKelly Mar 10 '16 at 22:45
-
May be your question is not clear so may some one downvote.. – Hitarth Mar 11 '16 at 10:13
-
Pretty damn clear. Batch update SQLite...is it possible, if so how? – ChuckKelly Mar 14 '16 at 09:17
1 Answers
2
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;
}

DoctorDbx
- 328
- 4
- 12