Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID
Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.

sqlite database works fine on simulator, but is readonly on device

yezaevyezaev Posts: 94Registered Users
Anytime I step my insert statements they return result code 8, SQLITE_READONLY. Has anyone seen this?
Post edited by yezaev on

Replies

  • FlyingDiverFlyingDiver Posts: 997Registered Users
    yezaev;78592 said:
    Anytime I step my insert statements they return result code 8, SQLITE_READONLY. Has anyone seen this?
    Where is the database on the phone? In the resources directory, or did you copy it to the Documents directory? The resources directory is read-only.

    joe
  • vinced45vinced45 Posts: 23Registered Users
    FlyingDiver;78602 said:
    Where is the database on the phone? In the resources directory, or did you copy it to the Documents directory? The resources directory is read-only.

    joe
    You might need to create an editable verision. Try this.

    - (void)createEditableCopyOfDatabaseIfNeeded
    {
    // First, test for existence.
    BOOL success;
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSError *error;
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:@\"database_name.sql\"];
    success = [fileManager fileExistsAtPath:writableDBPath];
    // NSLog(@\"path : %@\", writableDBPath);
    if (success) return;
    // The writable database does not exist, so copy the default to the appropriate location.
    NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@\"database_name.sql\"];
    success = [fileManager copyItemAtPath:defaultDBPath toPath:writableDBPath error:&error];
    if (!success)
    {
    NSAssert1(0, @\"Failed to create writable database file with message '%@'.\", [error localizedDescription]);
    }
    }


    Then read from the newly created path
  • yezaevyezaev Posts: 94Registered Users
    Ack thanks to both of you! Somehow I've just never ended up needing to write to any files in the resources directory and hadn't realized they were readonly. Many thanks.
  • AthAth Posts: 53Registered Users
    Sorry for picking up this thread, but I didn't want to start a new one, since I have a similar problem.

    First, I've already chmoed MyApp.db (database) and my project folder /MyApp/ both to 777, but I still getting the same error as OP. How did you solved/solve this problem specially? Is it possible to set Resources to writable? If yes, how?

    Thanks in advance!
    What the soul hides, blood tells!
  • smashersmasher Posts: 3,858Registered Users
    Ath;97470 said:
    Sorry for picking up this thread, but I didn't want to start a new one, since I have a similar problem.

    First, I've already chmoed MyApp.db (database) and my project folder /MyApp/ both to 777, but I still getting the same error as OP. How did you solved/solve this problem specially? Is it possible to set Resources to writable? If yes, how?

    Thanks in advance!
    You do not want to write to resources. "Resources" means the bundle, which will get replaced with a new version if you ever release an update/upgrade.

    If your app needs to make changes to the database file, you should use vinced45's code to copy the database to the documents folder, and open it from there.
    [IMG]http://a5.mzstatic.com/us/r1000/042/Purple/2d/83/7d/mzm.cimuqibw.75x75-65.jpg[/IMG] <a href="http://itunes.apple.com/us/app/tiny-nightclub/id418478743?mt=8" ta
  • AthAth Posts: 53Registered Users
    Smasher, thanks for the detailed explanation! I got it working! :) Although it takes a time to update, but i'll see what's going on... :P

    Thanks again!
    What the soul hides, blood tells!
Sign In or Register to comment.