【问题标题】:How to migrate *.sqlite database via FMDBMigrationManager?如何通过 FMDBMigrationManager 迁移 *.sqlite 数据库?
【发布时间】:2015-05-28 22:29:59
【问题描述】:

我正在使用 FMDB IOS 框架来管理我的 sqlite 数据库。

但现在我有第二个版本的数据库,所以我需要更新我的 sqlite 文件(在安装了应用程序的设备上)

这是我的步骤:(数据库在 Application Support/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 是 .../Library/Application Support/db/db.sqlite

但在此步骤之后,我没有迁移,并且 migrateDatabaseToVersion:progress:error: 中的 0 pendingVersions:

我做错了什么?谢谢。

【问题讨论】:

    标签: ios iphone database sqlite fmdb


    【解决方案1】:

    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];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-06
      • 1970-01-01
      • 2010-12-05
      • 2021-09-21
      • 1970-01-01
      • 1970-01-01
      • 2016-09-04
      • 2021-05-24
      相关资源
      最近更新 更多