Hello Every1,
i maintain a sqlite db in my iPhone app so, i was wondering how u could persist a single version and updated one.
its said that if want to make updates to the db u should copy it to the documents folder
on my iPhone simulator the documents folder changes like everytime i open the app
if its copied and changes was made .. how come the app reflect the updates to the db in my app bundle so when the app is up again the app copies the db again from my bundle to the documents folder to be able to make changes to it..
my problem is that sometimes i make changes and load the app again to find that the changes are gone!
all what i have done:
1-created the db using terminal on a certain path and on resources folder in xcode right clicked add existing file 2-i do this each time i load the app : -(void)DBinit { // Setup some globals databaseName = @"articlesdb.sql";
// Get the path to the documents directory and append the databaseName
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [documentPaths objectAtIndex:0];
databasePath = [[documentsDir stringByAppendingPathComponent:databaseName] copy];
NSLog(databasePath);
// Execute the "checkAndCreateDatabase" function
[self checkAndCreateDatabase];
}
-(void)checkAndCreateDatabase { // Check if the SQL database has already been saved to the users phone, if not then copy it over BOOL success;
// Create a FileManager object, we will use this to check the status
// of the database and to copy it over if required
NSFileManager *fileManager = [NSFileManager defaultManager];
// Check if the database has already been created in the users filesystem
success = [fileManager fileExistsAtPath:databasePath];
// If the database already exists then return without doing anything
if(success)
{
[fileManager removeItemAtPath:databasePath error:nil];
return;
}
// If not then proceed to copy the database from the application to the users filesystem
// Get the path to the database in the application package
NSString *databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:databaseName];
// Copy the database from the package to the users filesystem
[fileManager copyItemAtPath:databasePathFromApp toPath:databasePath error:nil];
[fileManager release];
}
appreciate your help