dimanche 24 mai 2015

FMDB. When closing application, nothing is saved in database

I'm using FMBD framework for working with sqlite database. This is my code for starting work with database:

NSString *docsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
    NSString *dbPath   = [docsPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.%@",


                                          PTKDatabaseName,
                                                               PTKDatabaseType]];
[[NSFileManager defaultManager] removeItemAtPath:dbPath error:nil];
if (![[NSFileManager defaultManager] fileExistsAtPath:dbPath isDirectory:false]) {
    NSString *bundleDBPath = [[NSBundle mainBundle] pathForResource:PTKDatabaseName ofType:PTKDatabaseType];
    [[NSFileManager defaultManager] copyItemAtPath:bundleDBPath toPath:dbPath error:nil];
}

self.database = [FMDatabase databaseWithPath:dbPath];

And i'm using execiteUpdate for inserting new values into table.

NSString *text      = tweet.text;
    NSNumber *id        = tweet.id;
    NSString *created_at  = [tweet.created_at stringValue];

    NSString *sqlSL = @"INSERT INTO Tweet VALUES (:id, :text, :created_at)";
    NSDictionary *paramethers = @{
                                  @"id"         : id,
                                  @"text"       : text,
                                  @"created_at" : created_at};
    [self.database executeUpdate:sqlSL withParameterDictionary:paramethers];

All works perfectly, values exist in tables and i can get them.

But when i'm fully closing application and there opening agin, my database is empty. What am I doing wrong?

Aucun commentaire:

Enregistrer un commentaire