데이터베이스 FMDB는 자체적으로 SQLite 데이터베이스에 저장됩니다. FMDB를 사용하여 문서 폴더에있는 SQLite 데이터베이스를 엽니 다 (번들에서 복사하거나 프로그래밍 방식으로 생성 한 데이터베이스). 번들의 데이터베이스를 변경하지 마십시오 (심지어 데이터베이스가있는 경우).
NSString *bundlePath = [[NSBundle mainBundle] pathForResource:@"Base" ofType:@"db"];
NSString *documentsFolder = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
NSString *documentsPath = [documentsFolder stringByAppendingPathComponent:@"Base.db"];
NSFileManager *fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath:documentsPath]) {
NSError *error;
BOOL success = [fileManager copyItemAtPath:bundlePath toPath:documentsPath error:&error];
NSAssert(success, @"%s: copyItemAtPath error: %@", __FUNCTION__, error);
}
// now FMDB can use the database at `documentsPath`
출처
2014-01-19 15:08:03
Rob
FMDB는 SQLite 데이터베이스를 _is_을 저장하는 데이터베이스, 그래서 나는 ':
는 일반적으로 데이터베이스가 문서에 존재하는지 확인한다 무엇을 할 것 인아닌 경우는 번들에서가 복사 네가 묻는 것이 불분명 해. FMDB를 사용하여 문서 폴더에있는 SQLite 데이터베이스를 엽니 다 (번들에서 복사하거나 프로그래밍 방식으로 생성 한 데이터베이스). 번들의 데이터베이스를 변경하지 마십시오 (심지어 데이터베이스가있는 경우). 질문을 명확히 할 수 있습니까? – Rob
알았어요! 나는 내 문제를 해결했다. 방금 다음 문자열을 썼습니다 : NSString * path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent : @ "Base.db"]; NSString * path2 = [DOCUMENTS stringByAppendingPathComponent : @ "Base.db"]; if (! [[NSFileManager defaultManager] fileExistsAtPath : path2]) { NSData * xmlData = [NSData dataWithContentsOfFile : path]; [xmlData writeToFile : path2 atomically : YES]; } – Ike
예. 'NSData'를 통해 round-tripping하는 것이 아니라'copyItemAtPath'를 사용하는 것이 좋습니다. 그러나 이것은 본질적으로 옳습니다. – Rob