2010-09-17 179 views
1

我使用的是“著名的” :)功能createEditableCopyOfDatabaseIfNeeded仅供如果没有数据库的副本,在iPhone应用程序创建我的数据库的可编辑副本。该功能复制的文件目录中的原始数据库..很简单.. 但现在我陷入困境,因为我不知道为什么,但与SDK 3.2.3在iOS 4.1中的功能copy my db .... EMPTY !!!createEditableCopyOfDatabaseIfNeeded创建数据库的空副本!

下面是代码:

- (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]); 
    } 
} 

的db是完全正确!我可以用firefox的sqlite插件读取原始数据库! 有什么帮助吗?

Thx很多!!!

回答

2

仅用于测试目的:

尝试先删除现有的数据库。我猜测,当你在编写代码和调试时,你会在这个例程存在之前运行你的应用程序。 SQLite会为你创建一个空的数据库。

+0

或者直接从手机中删除整个应用程序。 – 2012-01-14 14:16:36

相关问题