Sean Smyth
Sean Smyth

Reputation: 1581

Opening SQL with Objective-C

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

Answers (1)

Midhun MP
Midhun MP

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

Related Questions