(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];
[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]) { // … } }];
[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]) { // … } }];
ui18-Database operations: SQL FMDB