Reputation:
Hi new Iphone programmer here
I'm trying to connect to my sqlite database but having problems, I have the sqlite library, and the database file in my supporting files folder, it doesn't connect when i load the simulator
(void)viewDidLoad
{
[super viewDidLoad];
NSString *docsDir;
NSArray *dirPaths;
//Get the documents directory
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
docsDir = [dirPaths objectAtIndex:0];
//Builds the path to the database file
databasePath = [[NSString alloc]
initWithString:[docsDir stringByAppendingPathComponent:@"PetrolWatch.sqlite"]];
NSFileManager *fileMgr = [NSFileManager defaultManager];
if([fileMgr fileExistsAtPath:databasePath]== YES)
{
lblStatus.text = @"Path Exists";
}
else
{
lblStatus.text = @"Failed to open db";
}
}
Thank you in advance
Upvotes: 0
Views: 437
Reputation: 43330
You're looking for the SQLite file in your documents directory, despite the fact that resources are loaded to the application bundle, then copied over to the documents directory manually. Because I see no code that moves the file out of the bundle, perhaps [[NSBundle mainBundle]pathForResource:]
would be a more fruitful way of checking for the existence of your file (nil path = no resource).
Upvotes: 1