ifish/Ifish/Utinitys/DB/IfishDBHelper.m

50 lines
1.2 KiB
Objective-C

//
// IfishDBHelper.m
// Ifish
//
// Created by imac on 16/1/26.
// Copyright © 2016年 imac. All rights reserved.
//
#import "IfishDBHelper.h"
@implementation IfishDBHelper
static FMDatabaseQueue *databaseQueue = nil;
+(FMDatabaseQueue *) getDatabaseQueue
{
if (!databaseQueue) {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDirectory = [paths objectAtIndex:0];
NSString *dbPath = [documentDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"IfishDB"]];
databaseQueue = [FMDatabaseQueue databaseQueueWithPath:dbPath];
}
return databaseQueue;
}
+ (BOOL) isTableOK:(NSString *)tableName withDB:(FMDatabase *)db
{
BOOL isOK = NO;
FMResultSet *rs = [db 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)
{
isOK = NO;
}
else
{
isOK = YES;
}
}
[rs close];
return isOK;
}
@end