[Fmdbmanager indatabase:^ (Fmdatabase *db) {[db shouldcachestatements]; Start transaction [DB BeginTransaction]; BOOL isrollback = NO; @try {for (nsdictionary *dic in resultdic[@ "events"]) {//replace into first attempt to insert data To the table, 1. If you find that this row of data is already in the table (judging by a primary key or a unique index), the row data is first deleted and then the new data is inserted. 2. Otherwise, insert the new data directly. NSString *sql = [nsmutablestring stringwithformat:@ "replace into events values ('%@ ', '%@ ', '%@ ', '%@ ', ' 0 ', ' 0 ')", dic[@ "id "],dic[@" title "],dic[@" src "],dic[@" type "]; BOOL a = [db Executeupdate:sql]; if (!a) {NSLog (@ "Insert failed 1"); }}} @catch (NSException *exception) {isrollback = Y ES; [DB rollback]; } @finally {if (!isrollback) { [DB commit]; } } }]; }
SQLite BULK INSERT, repeat insert (update)