我正在使用“着名”:)函数createEditableCopyOfDatabaseIfNeeded在iphone应用程序中创建我的数据库的可编辑副本。该函数仅在文档目录中没有副本时复制原始数据库。 db ..很简单.. 但是现在我遇到了麻烦,因为我不知道为什么但是在iOS 4.1中使用SDK 3.2.3这个函数复制我的数据库.... EMPTY !!!
以下是代码:
- (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插件读取原始数据库! 有什么帮助吗?
很多!!!
答案 0 :(得分:2)
仅用于测试目的:
首先尝试删除现有数据库。我猜你正在编写代码和调试时,你会在这个例程存在之前运行你的应用程序。 SQLite会为你创建一个空数据库。