FMDB中判断Sqlite的表是否存在

网上很多人没给出最终判断方法,我这里给个简单的


// 判断是否存在表

- (BOOL) isTableOK:(NSString *)tableName
{
    FMResultSet *rs = [self.DB executeQuery:@"select count(*) as 'count' from sqlite_master where type ='table' and name = ?", tableName];
    while ([rs next])
    {
        // just print out what we've got in a number of formats.
        NSInteger count = [rs intForColumn:@"count"];
        NSLog(@"isTableOK %d", count);
        
        if (0 == count)
        {
            return NO;
        }
        else
        {
            return YES;
        }
    }

    return NO;
}



你可能感兴趣的:(sqlite,table)