0427 数据库 是否存在文件名
//Documents:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
//username md5
const char *cStr = [userName UTF8String];
unsigned char result[16];
CC_MD5(cStr, (CC_LONG)strlen(cStr), result);
NSString* MD5 = [NSString stringWithFormat:@"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",result[0], result[1], result[2], result[3], result[4], result[5], result[6], result[7],result[8], result[9], result[10], result[11],result[12], result[13], result[14], result[15]];
//数据库文件夹
NSString * documentsDirectory = [[paths objectAtIndex:0] stringByAppendingPathComponent:MD5];
NSFileManager *fileManager = [NSFileManager defaultManager];
BOOL isDir = FALSE;
BOOL isDirExist = [fileManager fileExistsAtPath:documentsDirectory isDirectory:&isDir];
if(!(isDirExist && isDir)) {
BOOL bCreateDir = [fileManager createDirectoryAtPath:documentsDirectory withIntermediateDirectories:YES attributes:nil error:nil];
if(!bCreateDir) {
MCLog(@"Create Database Directory Failed.");
}
MCLog(@"%@", documentsDirectory);
}
NSString *dbPath = [documentsDirectory stringByAppendingPathComponent:@"im_demo.db"];
MCLog(@"im_demo.db 数据库地址 ===%@",dbPath);
if (self.dataBase) {
[self.dataBase close];
self.dataBase = nil;
}
self.dataBase = [FMDatabase databaseWithPath:dbPath];
[self.dataBase open];
[self memberTableCreate];//成员表 gzz0427
[self IMGroupIDTableCreate];
[self IMGroupNoticeTableCreate];
[self sessionTableCreate]; //会话表 gzz0427
[self IMTriggerCreate]; //触发器???