我正在使用“著名” :)函数createEditableCopyOfDatabaseIfNeeded在iphone应用程序中创建我的数据库的可编辑副本。该函数仅在还没有数据库副本的情况下才将原始数据库复制到documents目录中。很简单..
但是现在我很麻烦,因为我不知道为什么,但是在iOS 4.1中使用SDK 3.2.3时,该功能复制了我的数据库...。
这是代码:
- (void)createEditableCopyOfDatabaseIfNeeded
{
// First, test for existence.
BOOL success;
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:@"funghi.sql"];
success = [fileManager fileExistsAtPath:writableDBPath];
if (success) return;
// The writable database does not exist, so copy the default to the appropriate location.
NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"funghi.sql"];
success = [fileManager copyItemAtPath:defaultDBPath toPath:writableDBPath error:&error];
if (!success) {
NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]);
}
}
数据库已满且正确!我可以用firefox的sqlite插件读取原始数据库!
有什么帮助吗?
多谢!!!
最佳答案
仅出于测试目的:
尝试首先删除现有数据库。我猜想您在编写代码和调试程序时就已经在该例程存在之前运行了应用程序。 SQLite会为您创建一个空数据库。
关于iphone - createEditableCopyOfDatabaseIfNeeded创建db的空副本!,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3737832/