Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>here how i done this create a class called DBManagement and in m file implement these methods.also put this line in implementation file above @implementation line </p> <p>static sqlite3 *CHManagement = nil;</p> <pre><code>-(NSString *) getDBPath { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *MyDatabasePath = [documentsDirectory stringByAppendingString:@"/CHManagement.sqlite"]; return MyDatabasePath; } -(void) checkDataBase { NSLog(@"CheckDatabase Called"); NSFileManager *fileManager=[NSFileManager defaultManager]; NSError *error=[[[NSError alloc]init] autorelease]; NSString *dbPath = [self getDBPath]; BOOL success=[fileManager fileExistsAtPath:dbPath]; if(!success) { NSString *defaultDBPath=nil; defaultDBPath=[[[NSBundle mainBundle]resourcePath]stringByAppendingPathComponent:@"CHManagement.sqlite"]; success=[fileManager copyItemAtPath:defaultDBPath toPath:dbPath error:&amp;error]; if(!success) { NSAssert1(0,@"failed to create database with message '%@'.",[error localizedDescription]); } } else { sqlite3 *MyDatabase; NSInteger VersionNumber=0; sqlite3_stmt *CompiledStatement=nil; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *MyDatabasePath = [documentsDirectory stringByAppendingString:@"/CHManagement.sqlite"]; if(sqlite3_open([MyDatabasePath UTF8String],&amp;MyDatabase) == SQLITE_OK) { sqlite3_prepare_v2(MyDatabase, "select appVersionNo from VersionInfo", -1, &amp;CompiledStatement, NULL); while(sqlite3_step(CompiledStatement) == SQLITE_ROW) { VersionNumber=sqlite3_column_int(CompiledStatement,0); } sqlite3_reset(CompiledStatement); sqlite3_finalize(CompiledStatement); sqlite3_close(MyDatabase); } if (VersionNumber!=1) { [self deleteDatabase]; NSString *defaultDBPath=[[[NSBundle mainBundle]resourcePath]stringByAppendingPathComponent:@"CHManagement.sqlite"]; success=[fileManager copyItemAtPath:defaultDBPath toPath:dbPath error:&amp;error]; if(!success) { NSAssert1(0,@"failed to create database with message '%@'.",[error localizedDescription]); } } } } - (void)deleteDatabase { NSLog(@"Delete Database Called"); NSError **error=nil; NSFileManager *FileManager = [NSFileManager defaultManager]; NSString *databasepath = [self getDBPath]; BOOL success = [FileManager fileExistsAtPath:databasepath]; if(success) { [FileManager removeItemAtPath:databasepath error:error]; } } </code></pre> <p>with these methods you can easily load database into iphone document folder of the app. Sorry about the formatting. and appVersionNo is a field in a tableCalled versionInfo the default value is 1</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload