iphone - createEditableCopyOfDatabaseIfNeeded创建db的空副本!

标签 iphone xcode sqlite

我正在使用“著名” :)函数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/

相关文章:

iphone - 带按钮的 UIscrollview 中的动画

iphone - CoreData 中保存的字符串返回 <null> 和字符串。为什么?

iphone - 现在运行事件指示器

ios - Tableview 标题与单元格重叠

ios - 如何在 Storyboard 上创建 Segue,从以编程方式注册的 UICollectionViewCell 到新的 UIViewController?

php - PDO SQLite 查询零结果问题

ios - 在线和离线管理 iPhone 应用程序

iphone - 如何只加载网页的主体

ios - 启动框架/Info.plist : No such file or directory 时所有框架错误

java - 如何显示ListView,并在SQLite数据库的3列上存储3个编辑文本?