0

I can't update my database: I connect to it and then I use this function but it must execute but no update:

- (BOOL) updatePoint:(NSString *) word {

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *path = [documentsDirectory stringByAppendingPathComponent:@"master.sqlite"];
    sqlite3_stmt *statement;
    if (sqlite3_open([path UTF8String], &database) == SQLITE_OK) {
        int newPoint = point + 1;
        NSString *sql = [NSString stringWithFormat:@"UPDATE %@ SET Point='%d' WHERE Parola=?", 
                         dictionaries1[[[word substringWithRange:NSMakeRange(0,1)] intValue]-1],newPoint];

        if(sqlite3_prepare_v2(database, [sql UTF8String], -1, &statement, NULL)==SQLITE_OK)
            sqlite3_bind_text(statement,1,[word UTF8String] ,-1, SQLITE_TRANSIENT);
        sqlite3_step(statement); 

        sqlite3_finalize(statement);
        //sqlite3_reset(statement);
        sqlite3_close(database);
        return YES;
    } else
        return NO;
}

What's wrong?

4
  • how do you know that it is not updated? Commented Feb 16, 2011 at 9:00
  • because, I extract point(that is the value that I wanto to update) from database and point is the same, always 2, instead it'll be the first time 2, the second 3, the third 4..ecc.. Commented Feb 16, 2011 at 9:27
  • i mean do you get that value programmatically or manually using terminal ? Commented Feb 16, 2011 at 9:30
  • When you have db file inside your Xcode project it is copied to bundle during install. When you're installing app on simulator the application with it's resources is usually overridden (so your changes may be discarded). Try to add some reference to external file (e.g. /test.db in your root directory). Commented Feb 16, 2011 at 10:38

1 Answer 1

0

you can look at this, the update code above seems fine but the only problem that might come may be due to database being overwritten or it might not be present at the specified location. Problem with inserting data into a table

You can replace the insert code with your update statements

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.