标签:
- (BOOL)updateOneBooktempID:(NSString *)bookid WithTable:(NSString*)tabName
{
NSFileManager * fileManager = [NSFileManager defaultManager];
NSString* filename = [self getDBPath];
BOOL succ = NO;
if ([fileManager fileExistsAtPath:filename])
{
FMDatabase *db = [FMDatabase databaseWithPath:filename];
if ([db open])
{
//判断字段是否存在
if ([db columnExists:BRA inTableWithName:tabName]) {
NSString *update = [NSString stringWithFormat:@"UPDATE %@ SET bookID = ? WHERE bra = ?",tabName];
succ = [db executeUpdate:update,bookid,@"第一次新增字段"];
}else{
NSString *sql = [NSString stringWithFormat:@"ALTER TABLE %@ ADD %@ VARCHAR",tabName,@"bra"];
[db executeUpdate:sql];
NSString *update = [NSString stringWithFormat:@"UPDATE %@ SET bookID = ? WHERE bra = ?",tabName];
succ = [db executeUpdate:update,bookid,@"新增字段"];
}
}
[db close];
}
return succ;
}
标签:
原文地址:http://www.cnblogs.com/woaixixi/p/5302017.html