I’m using the “famous” 🙂 function createEditableCopyOfDatabaseIfNeeded for create an editable copy of my db in an iphone app.. The function copy the original db in the documents directory only if there isn’t already a copy of the db.. pretty simple..
but now I’m in trouble because I don’t know why but with SDK 3.2.3 in iOS 4.1 the function copy my db…. EMPTY!!!
Here is the code:
- (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]);
}
}
The db is full and correct! I can read the original db with the sqlite plugin of firefox!
Any help?
Thx a lot!!!
For testing purposes only:
Try to delete the existing database first. I’m guessing that as you were writing code and debugging you ran your application before this routine existed. SQLite would have created an empty database for you.