Reputation: 1581
I have an sql file in my supporting files. How can I open this file so that I can start using SQL commands to get the information that I want? I've tried a couple different syntaxes, and the last time I tried I ended up screwing up the whole application because I couldn't remember what I had changed.
Upvotes: 0
Views: 183
Reputation: 107231
If you are using sqlite 3. Then,
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* documentsDirectory = [paths lastObject];
NSString* dbPath = [documentsDirectory stringByAppendingPathComponent:@"database.sqlite"];
if(sqlite3_open([dbPath UTF8String], &dataBase) == SQLITE_OK)
{
NSLog(@"Opened Database");
//Your code
}
else
{
NSLog(@"Failed to open database");
sqlite3_close (database);
}
Upvotes: 1