我正在从事IPAD项目。该项目包含1个sqlite数据库。我使用了FMDatabase和FMDatabaseQueue。
fmdb = [FMDatabase databaseWithPath:path];
fmdbQ= [FMDatabaseQueue databaseQueueWithPath:path];
当我想使用查询时,我使用了代码
[fmdbQ inDatabase:^(FMDatabase *db) {
NSString *sqlQry = [NSString stringWithFormat:@"select * from Product"];
FMResultSet *rs = [db executeQuery:sqlQry];
}
现在,我想再添加一个sqlite文件。因此,我使用ATTACH语句合并了两个sqlite文件。
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"file1.sqlite"];
NSString *path2 = [documentsDirectory stringByAppendingPathComponent:@"file2.sqlite"];
fmdb = [FMDatabase databaseWithPath:path];
fmdbQ= [FMDatabaseQueue databaseQueueWithPath:path];
NSString *attachSQL = [NSString stringWithFormat: @"ATTACH DATABASE \'%@\' AS productDB", path2];
bool success = [fmdb executeStatements:attachSQL];
附加后,我只能使用 FMResultSet * rs = [fmdb executeQuery:sqlQry];
无法执行FMDatabaseQueue函数。