hey u need to add the sqlite file to your xcode project first - most appropriate place is in the resources folder
then in your app delegate code file, in the appDidFinishLaunching method, you need to first check if a writable copy of the the sqlite file has already been created - ie: a copy of the sqlite file has been created in the users document folder on the iphone's file system, if yes you dont do anything (else you would overwrite it with the default xcode sqlite copy)
if no then you copy the sqlite file there - to make it writable
see below code example to do this: this has been taken from apple's sqlite books code sample where this method is called from the app delegates appDidFinishLaunching method
// Creates a writable copy of the bundled default database in the application Documents directory.
- (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:@"bookdb.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:@"bookdb.sql"];
success = [fileManager copyItemAtPath:defaultDBPath toPath:writableDBPath error:&error];
if (!success) {
NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]);
}
}