2015-03-25 85 views
0

我正在使用FMDB IOS框架來管理我的sqlite數據庫。如何通過FMDBMigrationManager遷移* .sqlite數據庫?

但現在我有我的數據庫的第二個版本,所以我需要更新我的sqlite的文件(在安裝了應用程序的設備)

這裏是我的步驟:(數據庫在應用程序支持/ DB/db.sqlite )

  1. 創造第二。 sqlite的文件(名爲 「2_db.sqlite」),並將其複製到我的主束
  2. 使用上每到這個代碼開始

    -(void)migrateWithDBAtPath:(NSString *)dbPath { 
        FMDBMigrationManager *manager = [FMDBMigrationManager managerWithDatabaseAtPath:dbPath migrationsBundle:[NSBundle mainBundle]]; 
        NSError *error = nil; 
        BOOL success = [manager migrateDatabaseToVersion:UINT64_MAX progress:nil error:&error]; 
    } 
    

DBPATH是... /庫/ Application Support/DB/db.sqlite

但這步驟後,我在migrateDatabaseToVersion沒有遷移和0 pendingVersions:進度:錯誤:

我在做什麼錯?謝謝。

回答

0

Objective-C的方式:

FMDBMigrationManager * manager = [FMDBMigrationManager managerWithDatabaseAtPath: @"Path to your db" migrationsBundle:[NSBundle mainBundle]]; 
    //Path to the sql file with the statements to apply to your db 
    NSString * expectedPath = [[NSBundle mainBundle] pathForResource: @"1" ofType: @"sql"]; 
    FMDBFileMigration * fileMigration = [FMDBFileMigration migrationWithPath: expectedPath]; 
    //Apply the statements in 1.sql 
    BOOL successFileMigration =[ fileMigration migrateDatabase: [manager database] error:nil];