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 8481937
In Process

The Archive Base Latest Questions

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

I could read from my SQLITE DB, but unable to update it. I wonder

  • 0

I could read from my SQLITE DB, but unable to update it. I wonder if the database is writable.

When i copy the SQL to the SQL console the code gets executed successfully. So there’s no problem with the SQL.

-(BOOL) updateScores{
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0]; 
    NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:@"uniques.sqlite"];

    FMDatabase* db = [FMDatabase databaseWithPath:writableDBPath];
    BOOL success;

    if ([db open]) {

        if ([db hadError]) {
            NSLog(@"DB Error %d: %@", [db lastErrorCode], [db lastErrorMessage]);
        } 

        success = [db executeUpdate:[NSString stringWithFormat:@"UPDATE Score SET answer='11' WHERE name LIKE 'jack'"]];

        if (success) {
            NSLog(@"OK");
        }else {
            NSLog(@"FAIL");
        }

        [db close];
    }else {
        NSLog(@"Problem with DB");
    }

    return success; 
}
  • 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-10T19:41:45+00:00Added an answer on June 10, 2026 at 7:41 pm

    Always pass the arguments to SQL query as an object type, please look at the way arguments are passed to the SQL query. Even if you are passing a number, pass it as

    [NSNumber numberWithInt:someValue] 
    

    Try this:

    -(BOOL) updateScores
    {
      NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
      NSString *documentsDirectory = [paths objectAtIndex:0]; 
      NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:@"uniques.sqlite"];
    
      FMDatabase* db = [FMDatabase databaseWithPath:writableDBPath];
      BOOL success = NO;
    
      if ([db open] != YES) {
            NSLog(@"DB Error %d: %@", [db lastErrorCode], [db lastErrorMessage]);
            return NO; //VERY IMPORTANT
        } 
    
      [db beginTransaction];
        success = [db executeUpdate:@"UPDATE scores SET answer = ? WHERE name like ?", @"1", @"jack"]; 
    
        if (success) {
            NSLog(@"OK");
            [db commit];
            [db close];
        }else {
            NSLog(@"FAIL");
        }
    
       return success; 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I read the documentation @ http://www.sqlite.org/lang_select.html , but could not understand if LIMIT works
How could this be happening? sqlite> select read, text from message; 1|No just got
I am trying to directly import an SQL file from a SQLite database into
I was wondering if i could safely read from an XmlDocument object using SelectNodes()
I'm using fopen to read from a file $fh = fopen($path, 'r') or die('Could
Could you guys give me an example how to read and write from/to xml
How could you do to read a web.config file from inside a aspx file?
I read somewhere that somebody could access a config value during run time but
I could find the answer if I read a complete chapter/book about multithreading, but
I am Trying to read data from text files and save tokens in SQLite

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.