Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a new database programatically #12

Open
paresh-navadiya opened this issue Aug 27, 2015 · 1 comment
Open

Create a new database programatically #12

paresh-navadiya opened this issue Aug 27, 2015 · 1 comment

Comments

@paresh-navadiya
Copy link

Thanks for sharing!

Need to add these requirement.

@paresh-navadiya
Copy link
Author

Can someone add these method

-(NSError *)createNewDatabase:(NSString *)strDataBaseName
{
NSString *strDocsDir = nil;
NSArray *strDirPaths = nil;

// Get the documents directory
strDirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
//get path from array
strDocsDir = [strDirPaths objectAtIndex:0];

// Build the path to the database file
NSString *databasePath = [strDocsDir stringByAppendingPathComponent:strDataBaseName];

NSFileManager *filemgr = [NSFileManager defaultManager];

if ([filemgr fileExistsAtPath: databasePath ] == NO)
{
    const char *dbpath = [databasePath UTF8String];

    if (sqlite3_open(dbpath, &db) == SQLITE_OK)
    {
        //NSLog(@"database created");
        return nil;
    }
    else
    {
        NSString *strError = @"Failed to open/create database";
        NSError *errorQuery = [self createDBErrorWithDescription:strError andCode:kDBFailAtOpen];
        return errorQuery;
    }
}
else
{
    NSString *strError = @"Database already exists with same name";
    NSError *errorQuery = [self createDBErrorWithDescription:strError andCode:kDBFailAtCreate];
    return errorQuery;
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant