IOS -- SQLite数据库判断表是否存在

/**
 判断一张表是否已经存在
 @param tablename 表名
 */
- (BOOL)isExistTable:(NSString *)tablename{
    if ([_dataBase open]) {
        FMResultSet *rs = [_dataBase executeQuery:@"select count(*) as 'count' from sqlite_master where type ='table' and name = ?", tablename];
        while ([rs next]){
            NSInteger count = [rs intForColumn:@"count"];
            if (0 == count){
                return NO;
            }
            else{
                return YES;
            }
        }
        return NO;
    }
    return NO;
}

 



posted @ 2016-11-16 11:05  Crazy_ZY  阅读(2177)  评论(0编辑  收藏  举报