Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone:Removing/Deleting SQLite database?

Tags:

iphone

I know how to create sqlite database, inserting data into it, deleting row into it etc. through iPhone development, but i am trying to remove the entire database itself programmatically, but not getting any helps. Please someone guide me how to delete/remove the entire sqlite database itself from device thru code.

Thank you!

like image 259
Getsy Avatar asked Apr 08 '11 09:04

Getsy


2 Answers

If your db is in Documents you can try:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath =  [documentsDirectory stringByAppendingPathComponent:@"youdb.db"];

if([[NSFileManager defaultManager] fileExistsAtPath:filePath]){
    [[NSFileManager defaultManager] removeItemAtPath:filePath error:nil];
}
like image 79
Jorge Avatar answered Sep 17 '22 21:09

Jorge


Try

NSError *err;

NSFileManager *fm = [NSFileManager defaultManager];

err = nil;

NSString *deleteFileName = [NSString stringWithFormat:@"%@/FileName",[[NSBundle mainBundle] resourcePath]];

NSURL *url = [NSURL fileURLWithPath:deleteFileName];

[fm removeItemAtPath:[url path] error:&err];

if(err)

{

NSLog(@"File Manager: %@ %d %@", [err domain], [err code], [[err userInfo] description]);

}

else

{

NSLog(@"File %@ deleted.",fileName);

}
like image 23
Chetan Bhalara Avatar answered Sep 18 '22 21:09

Chetan Bhalara