Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8747257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:19:37+00:00 2026-06-13T12:19:37+00:00

I use a sqlite database for a project. I can do queries like SELECT

  • 0

I use a sqlite database for a project. I can do queries like SELECT but impossible to do INSERTs!
On the simulator the INSERT works properly. As soon as I compile on my iPod this error message appears: “attempt to write a readonly database”.

Thinking it is a right of the file I did a: chmod 777 mydatabase.sqlite
But that does not change!

I also tried as I have read on other site and copy the file to use his copy to have it all right, but to no avail.

Have you a solution?
Cordially.

PS: Here is my code:

for(NSDictionary *q in quotes) {
    sqlite3_stmt    *statement;
    sqlite3 *contactDB;
    const char *dbpath = [dbPath UTF8String];

    if (sqlite3_open_v2(dbpath, &contactDB, SQLITE_OPEN_READWRITE, NULL) == SQLITE_OK)
    {
        NSInteger identifiant = [[q objectForKey:@"id"] integerValue];
        NSString *texte = [q objectForKey:@"texte_english"];
        NSString *auteur = [q objectForKey:@"auteur"];
        NSString *date = [q objectForKey:@"date"];
        NSInteger auteurId = [[q objectForKey:@"auteur_id"] integerValue];
        NSInteger nbComments = [[q objectForKey:@"nb_comments"] integerValue];

        NSString *insertSQL = 
                [NSString stringWithFormat:@"INSERT INTO quotes (id, texte_english, auteur, date, auteur_id, nb_comments) VALUES (%d, \"%@\", \"%@\", \"%@\", \"%d\", \"%d\")", 
                                          identifiant, 
                                          texte, 
                                          auteur, 
                                          date, 
                                          auteurId, 
                                          nbComments];

        const char *insert_stmt = [insertSQL UTF8String];
        sqlite3_prepare_v2(contactDB, insert_stmt, -1, &statement, NULL);

        if (sqlite3_step(statement) != SQLITE_DONE)
        {
            NSLog(@"ERREUR1: %s",sqlite3_errmsg(contactDB));
        }
        sqlite3_finalize(statement);
        sqlite3_close(contactDB);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:19:38+00:00Added an answer on June 13, 2026 at 12:19 pm

    All you need to do is change the root that you are saving your SQLite file in you phone which is readonly at the moment. make these changes :

    Add these codes to your AppDelegate :

    .h file:

    @property (nonatomic,retain) NSFileManager *fileMgr;
    @property (nonatomic,retain) NSString *homeDir;
    @property (nonatomic,retain) NSString *title;
    

    .m file:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        [self checkAndCreateDatabase];
        return YES;
    }
    
    -(NSString *)GetDocumentDirectory{
        fileMgr = [NSFileManager defaultManager];
        homeDir = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
        return homeDir;
    }
    
        -(void) checkAndCreateDatabase{
        BOOL success;
        NSFileManager *fileManager = [NSFileManager defaultManager];
        NSString *databasePath = [self.GetDocumentDirectory stringByAppendingPathComponent:@"YOUR DATABASE NAME.sqlite"];
        success = [fileManager fileExistsAtPath:databasePath];
        if(success) {
            NSLog(@"working");
            return;}
        else{
            NSLog(@"notworking");
        NSString *databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"YOUR DATABASE NAME.sqlite"];
        [fileManager copyItemAtPath:databasePathFromApp toPath:databasePath error:nil];
        }
    }
    

    Also in your SQLite class add these lines :

    .h file:

    @property (nonatomic,retain) NSFileManager *fileMgr;
    @property (nonatomic,retain) NSString *homeDir;
    

    .m file:

    -(NSString *)GetDocumentDirectory{
        fileMgr = [NSFileManager defaultManager];
        homeDir = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
        return homeDir;
    }
    

    and also in INSERT and SELECT make these changes :

    NSString *dbPath = [self.GetDocumentDirectory stringByAppendingPathComponent:@"YOUR DATABASE NAME.sqlite"];
        const char *dbpath = [dbPath UTF8String];
    

    Hope it helps 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's the thing: In my Qt4.6-Project, I use a SQLite-Database. This database shouldn't be
What components can I use to use SQlite database with Delphi 6?
Please any on tell me can i use Sqlite database in my Windows Phone
I would like to use an SQLite database from Microsoft Access (access from- or
I'm trying to use DbLinq with a SQLite database, but I'm running into a
Today I use SQLite and send a database-file with the project. However I want
I have a django project that uses a sqlite database that can be written
In my project I use a sqlite database, unfortunately my friend have make an
I use a sqlite database in my project. The stored data in it must
I want to use SQLite as a database for my C++ project. I also

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.