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

  • SEARCH
  • Home
  • 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 8413475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:55:43+00:00 2026-06-10T00:55:43+00:00

I’m using a sqlite3 db that I open at the app delegate and then

  • 0

I’m using a sqlite3 db that I open at the app delegate and then at another view after pressing a button I execute an update statement that does not work.
The app delegate code:

- (BOOL) openDB{
    //NSMutableArray *logoArray = [[NSMutableArray alloc] init];
    @try {
        NSFileManager *fileMgr = [NSFileManager defaultManager];
        NSString *dbPath = [[[NSBundle mainBundle] resourcePath ]stringByAppendingPathComponent:@"SportsLogo.sqlite"];
        BOOL success = [fileMgr fileExistsAtPath:dbPath];
        if(!success)
        {
            NSLog(@"Cannot locate database file '%@'.", dbPath);
        }
        if(!(sqlite3_open([dbPath UTF8String], &db) == SQLITE_OK))
        {
            return NO;
        }
    }
    @catch (NSException *exception) {
            NSLog(@"An exception occured: %@", [exception reason]);
        }
        @finally {
            return YES;
        } 

    }

- (sqlite3 *) getDB{
    return db;
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    //MySportsLogosDB *myDB = [[MySportsLogosDB alloc]init];
    //NSMutableArray *myArray = [[NSMutableArray alloc]init];
    if ([self openDB] != YES){
        NSLog(@"Problem with opening the DB");
        return NO;
    }


    return YES;
}

Then when I press the button I run the following code:

-(IBAction)enter:(id)sender
{
    UIImage *answerImage = [UIImage imageNamed:[NSString stringWithFormat:@"%@%@",currentTitle, @".png"]];

    if ([[currentTitle lowercaseString] isEqualToString:logoNameText.text]){
        [imageGuessView setImage:answerImage];
        AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
      //  NSString *sql =[NSString stringWithFormat:@"select rowid from mytable where name = %@",str];

        NSString *sql = [NSString stringWithFormat:@"UPDATE LogosTbl set logoStatus = ?1 WHERE logoName = '%@'",[currentTitle lowercaseString]];

        sqlite3_stmt *sqlStatement;
        if(sqlite3_prepare_v2([appDelegate getDB], [sql UTF8String], -1, &sqlStatement, NULL) != SQLITE_OK)
        {
            NSLog(@"Problem with prepare statement");
            NSLog(@"%s",sqlite3_errmsg([appDelegate getDB]));
           // printf( "could not prepare statemnt: %s\n", sqlite3_errmsg(database) );

        }

        if(SQLITE_DONE != sqlite3_step(sqlStatement)){
            NSLog(@"Problem with UPDATE");
        }
 }
    else{
        NSLog(@"First No");
    }
}

The prepare is OK and also the step is OK but I don’t see that the data was updated.
The sqlite file is at my project tree in Xcode and it’s placed at the project directory in the file system with read & write permissions.

Thank you

  • 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-10T00:55:44+00:00Added an answer on June 10, 2026 at 12:55 am

    If the database file is in the project’s bundle then you can’t write anything there, as the bundle is readonly. Copy the database file to your documents folder and then you will have a writeable database. This example uses the FMDB wrapper for sqlite3:

    NSError  *error = nil;
    self.nfm = [[NSFileManager alloc] init];
    
    /*
     * if the database isn't in the Documents directory then copy from the bundle
     */
    
    NSArray  *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documentsPath = [paths objectAtIndex:0];
    
    NSString *documentsDatabasePath = [documentsPath stringByAppendingPathComponent:@"orders.db"];
    if(![self.nfm fileExistsAtPath:documentsDatabasePath]){
        NSString *bundlePath = [[NSBundle mainBundle] pathForResource:@"orders" ofType:@"db"];
        NSLog(@"Model init about to copy %@ to %@",bundlePath,documentsDatabasePath);
        [self.nfm copyItemAtPath:bundlePath toPath:documentsDatabasePath error:&error];
    }
    
    self.database = [FMDatabase databaseWithPath:documentsDatabasePath];
    if (![self.database open]) {
        if(trace) NSLog(@"Model: start: Could not open database in path \n%@",documentsDatabasePath);
        return nil;
    }
    
    
    if(trace) NSLog(@"Model: start: Opened database in path \n%@",documentsDatabasePath);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am using Paperclip to handle profile photo uploads in my app. They upload
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace

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.