SQLiteManager4iOS icon indicating copy to clipboard operation
SQLiteManager4iOS copied to clipboard

Need to add database first

Open paresh-navadiya opened this issue 10 years ago • 0 comments

Thanks for library. But need to add database

pragma mark -

pragma mark - Copy DataBase Method

-(void)copyDatabaseToDocumentDirectoryWithName:(NSString *)name { NSString *path = [[NSBundle mainBundle]pathForResource:[[name lastPathComponent]stringByDeletingPathExtension] ofType:[name pathExtension]];

if ([[NSFileManager defaultManager] fileExistsAtPath:path])
{
    NSArray *pathArray = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);
    NSString *documentsDirectory = [pathArray objectAtIndex:0];
    NSString *strFileDBPath = [documentsDirectory stringByAppendingPathComponent:name];

    if ([[NSFileManager defaultManager] fileExistsAtPath:strFileDBPath])//File exists in document directory
    {
        NSLog(@"Database exists");
    }
    else //File doesnot exists in document directory
    {
        //Need to copy file in document directory
        NSError *error = nil;
        if ([[NSFileManager defaultManager] copyItemAtPath:path toPath:strFileDBPath error:&error])
        { //copied successfully
            NSLog(@"Database copied");
        }
        else
        { //not copied
            NSLog(@"Database not copied");
        }
    }
}
else
{
    NSLog(@"Database file does not exists");
}

}

paresh-navadiya avatar Aug 03 '15 07:08 paresh-navadiya