Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

How to Create dbpath for database(iphone)
#1

-(NSString*)getdbpath
{
NSArray
*paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,
YES);

NSString *documentsdir=[paths objectAtIndex:0];
NSString *dbpath=[documentsdir
stringByAppendingPathComponentAngry"student1.sqlite"];

NSFileManager *fileManager=[NSFileManager defaultManager];

NSError *error;

BOOL success=[fileManager fileExistsAtPath:dbpath];

if(!success)
{
NSString *defaultpath=[[[NSBundle
mainBundle]resourcePath]stringByAppendingPathComponentAngry"student1.sqlite"];

success=[fileManager copyItemAtPath:defaultpath toPath:dbpath
error:&error];

if(!success)
NSAssert1(0,@"failed to create writable database.'%@'",
[error localizedDescription]);

}
NSLog(@"%@",dbpath);
return dbpath;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)