Susanna
Susanna

Reputation: 771

sqlite database opens fine on the iPhone simulator, but not on the device

Why would this run fine on the iPhone simulator... but the database can't be opened on an iPhone device?

sqlite3 *g_Db = nil;

BOOL OpenDatabase(NSString *databaseName)
{
    if(sqlite3_open([databaseName UTF8String], &g_Db) == SQLITE_OK)
    {
        NSLog(@"Opened db ok");
        return(YES);
    }
    else
    {
        NSLog(@"Can't open the db");
        sqlite3_close(g_Db);
        g_Db = nil;
        return(NO);
    }
}

Upvotes: 0

Views: 789

Answers (1)

Devin Ceartas
Devin Ceartas

Reputation: 4829

If the database doesn't exist yet and you are using SQLite's ability to create the database on first reference, then the file path has to point to the iPhone's document directory (or tmp) since you can write to the application bundle directory in the simulator but not on the device due to permissions. That's the only thing which jumps out at me as obviously different between the two which would effect SQLite code.

Upvotes: 1

Related Questions