FMDB (SQLite初探)

+ (instancetype)sharedInstance { static dispatch_once_t once; static id __singleton__; dispatch_once( &once, ^{ __singleton__ = [[self alloc] init]; } ); return __singleton__; }

/**

  • 打开数据库 - Data
    */
    - (void)opendb { if(db == nil){ NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentDirectory = [paths objectAtIndex:0]; NSString *dbPath = [documentDirectory stringByAppendingPathComponent:@"MyDatabase.db"]; db = [FMDatabase databaseWithPath:dbPath] ; if ([db open]) { NSLog(@"db打开成功"); [db executeUpdate:@"CREATE TABLE DataList (title text primary key not null, dataBase blob)"]; NSLog(@"db创建表成功"); NSLog(@"%@",db); }else{ NSLog(@"Could not open db."); } } }

你可能感兴趣的:(FMDB (SQLite初探))