??????????:????????FMDB????????????

 

/**
*  ???????????
*/
- (void)createDatabaseIfNeeded
{
// ?????·??
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory?? NSUserDomainMask?? YES);
NSString *doc = [paths objectAtIndex:0];
NSString *path = [doc stringByAppendingPathComponent:@"test.sqlite"];
NSFileManager * fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath:path] == NO) {
// create it
FMDatabase * db = [FMDatabase databaseWithPath:path];
if ([db open]) {
// ????User??
NSMutableString *sql = [NSMutableString stringWithFormat:@"%@"??@"CREATE TABLE User"];
[sql appendString:@"("];
[sql appendString:@"username varchar??"];
[sql appendString:@"password varchar"];
[sql appendString:@")"];
BOOL res = [db executeUpdate:sql];
if (!res) {
debugLog(@"error when creating table User");
} else {
debugLog(@"succ to creating table User");
}
[db close];
}
else {
debugLog(@"error when open db");
}
}
}

?????:FMDB????y??http://blog.devtang.com/blog/2012/04/22/use-fmdb/
???????????
????1?????????????????????????????????(??????????)????????????????????????
????2????????????????ж????????????????????????????/??????????????????????£??????°汾?????????????????????????汾?п??????°汾??(?ο?:http://blog.csdn.net/zyx586/article/details/18989199)????????°汾??????????????????κθ???????????μ?汾???????????????????????????????????????????e汾?????????′????????μ?????????????????