SQLite BULK INSERT, repeat insert (update)

Source: Internet
Author: User
Tags bulk insert sqlite

[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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.