SQLiteManager4iOS
SQLiteManager4iOS copied to clipboard
Create a new database programatically
Thanks for sharing!
Need to add these requirement.
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;
}
}