数据库操作

2016-10-31  本文已影响50人  DDY

FMDB

// 需要先创建数据库文件保存目录
if (![fileManager fileExistsAtPath:myPath]) {
        [fileManager createDirectoryAtPath:myPath withIntermediateDirectories:YES attributes:nil error:nil];
    }
// 拼接数据库路径
NSString *dbPath = [maskFilePath stringByAppendingPathComponent:@"user.sqlite"];
// 创建数据库
_dataBase = [FMDatabase databaseWithPath:dbPath];

NSString *sql = [NSString stringWithFormat:@"CREATE TABLE IF NOT EXISTS UserDataTable(u_id INTEGER PRIMARY KEY AUTOINCREMENT,  u_address TEXT)"];
BOOL result = [_dataBase executeUpdate:sql];
 [db executeUpdate:DDYStrFormat(@"CREATE INDEX IF NOT EXISTS index2 ON %@ (messageID)",tableName)];
上一篇下一篇

猜你喜欢

热点阅读