ui18-database operations: SQL FMDB

Source: Internet
Author: User

(a) FMDB open database, CREATE TABLE, query

(b) Execution statement:

(iii) Storage of data, model archiving, anti-archiving, and implementation of the Nscoding protocol an object can be converted to data. In essence, a nscoding protocol is implemented to comply with Nscoding protocol, and the method of implementing the protocol can be transformed into NSData.

(iv) Implementation of the encoding protocol two methods:

(v) Extract the same code, use the method, or call the duplicate code with block, and set the parameters and return values.

1/FOREIGN KEY constraint.

(vi)---Multi-threaded operation in Fmdb

    • If you want to do massive operations, you need to use a sub-thread to speed up
    • However, the database operation of a large amount of data, such as inserting 100,000 of data, you can open multiple sub-threads to operate, but you must use a synchronization thread, so that multiple threads execute one at a rather than cause database data confusion.
    • FMDatabaseQueueUse this class
    //FMDatabaseQueue的创建    FMDatabaseQueue *queue = [FMDatabaseQueue databaseQueueWithPath:path];
    • Basic operations
    [queue inDatabase:^(FMDatabase *db) {        [db executeUpdate:@"INSERT INTO t_student(name) VALUES (?)", @"Jack"];        [db executeUpdate:@"INSERT INTO t_student(name) VALUES (?)", @"Rose"];        [db executeUpdate:@"INSERT INTO t_student(name) VALUES (?)", @"Jim"];                FMResultSet *rs = [db executeQuery:@"select * from t_student"];        while ([rs next]) {            // …        }    }];
    • Using transactions
    [queue inTransaction:^(FMDatabase *db, BOOL *rollback) {        [db executeUpdate:@"INSERT INTO t_student(name) VALUES (?)", @"Jack"];        [db executeUpdate:@"INSERT INTO t_student(name) VALUES (?)", @"Rose"];        [db executeUpdate:@"INSERT INTO t_student(name) VALUES (?)", @"Jim"];        FMResultSet *rs = [db executeQuery:@"select * from t_student"];        while ([rs next]) {            // …        }    }];
    • Transaction rollback
      • *rollback = YES;

ui18-Database operations: SQL FMDB

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.