Burak Üstün

FMDB

Veritabanını uygulamanın içerisine kopyalamak için kullanılan kod: (Appdelegate içerisinde kullanılabilir)

   NSString *documentPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"stalker.db"];
    NSError *sqlPatchError;
    NSFileManager *sqlFileManager = [NSFileManager defaultManager];
    [sqlFileManager removeItemAtPath:documentPath error:&sqlPatchError];
    if (![sqlFileManager fileExistsAtPath: documentPath])
    {
        NSString *bundle = [[NSBundle mainBundle] pathForResource:@"stalker" ofType:@"db"];
        [sqlFileManager copyItemAtPath:bundle toPath: documentPath error:&sqlPatchError];
    }

INSERT METODU:

        NSString *documentPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"stalker.db"];
        FMDatabase *sqliteDb = [FMDatabase databaseWithPath:documentPath];
        [sqliteDb open];
        for(int i=0;i<self.followingArray.count;i++){
        [sqliteDb executeUpdate:@"INSERT INTO follows (userID) VALUES (?)",[[self.followingArray objectAtIndex:i] Id]];
        }

SELECT METODU:

FMResultSet *results = [sqliteDb executeQuery: [NSString stringWithFormat: @"SELECT * FROM follows"] ];
        while ( [results next] )
        {
            NSString *ad = [results stringForColumn:@"userID"];
            
            NSLog(@"FOLLOWS : %@",ad);
        }
March 24, 2017