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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:20:55+00:00 2026-05-14T01:20:55+00:00

I have a really frustrating error that I’ve spent hours looking at and cannot

  • 0

I have a really frustrating error that I’ve spent hours looking at and cannot fix. I can get data from my db no problem with this code, but inserting or updating gives me these errors:


*** Assertion failure in +[Functions db_insert_answer:question_type:score:], /Volumes/Xcode/Kanji/Classes/Functions.m:129

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Error inserting: db_insert_answer:question_type:score:'

Here is the code I’m using:


    [Functions db_insert_answer:[[dict_question objectForKey:@"JISDec"] intValue] question_type:@"kanji_meaning" score:arc4random() % 100];

    //update EF, Next_question, n here
    [Functions db_update_EF:[dict_question objectForKey:@"question"] EF:EF];

To call these functions:



+(sqlite3_stmt *)db_query:(NSString *)queryText{
    sqlite3 *database = [self get_db];
        sqlite3_stmt *statement;
    NSLog(queryText);
    if (sqlite3_prepare_v2(database, [queryText UTF8String], -1, &statement, nil) == SQLITE_OK) {
    } else {
        NSLog(@"HMM, COULDNT RUN QUERY: %s\n", sqlite3_errmsg(database));  
    }
    sqlite3_close(database);
    return statement;
}
+(void)db_insert_answer:(int)obj_id question_type:(NSString *)question_type score:(int)score{
    sqlite3 *database = [self get_db];
        sqlite3_stmt *statement;
    char *errorMsg;
    char *update = "INSERT INTO Answers (obj_id, question_type, score, date) VALUES (?, ?, ?, DATE())";
    if (sqlite3_prepare_v2(database, update, -1, &statement, nil) == SQLITE_OK) { 
        sqlite3_bind_int(statement, 1, obj_id);
        sqlite3_bind_text(statement, 2, [question_type UTF8String], -1, NULL);
        sqlite3_bind_int(statement, 3, score);
    } 
    if (sqlite3_step(statement) != SQLITE_DONE){
        NSAssert1(0, @"Error inserting: %s", errorMsg); 
    }
    sqlite3_finalize(statement);
    sqlite3_close(database);
    NSLog(@"Answer saved");
}
+(void)db_update_EF:(NSString *)kanji EF:(int)EF{
    sqlite3 *database = [self get_db];
        sqlite3_stmt *statement;
    //NSLog(queryText);
    char *errorMsg;
    char *update = "UPDATE Kanji SET EF = ? WHERE Kanji = '?'";
    if (sqlite3_prepare_v2(database, update, -1, &statement, nil) == SQLITE_OK) {
        sqlite3_bind_int(statement, 1, EF);
        sqlite3_bind_text(statement, 2, [kanji UTF8String], -1, NULL);
    } else {
        NSLog(@"HMM, COULDNT RUN QUERY: %s\n", sqlite3_errmsg(database));  
    }
    if (sqlite3_step(statement) != SQLITE_DONE){
        NSAssert1(0, @"Error updating: %s", errorMsg); 
    }
    sqlite3_finalize(statement);
    sqlite3_close(database);
    NSLog(@"Update saved");
}

+(sqlite3 *)get_db{
    sqlite3 *database;

    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSString *copyFrom = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"/kanji_training.sqlite"];
    if([fileManager fileExistsAtPath:[self dataFilePath]]) { 
        //NSLog(@"DB FILE ALREADY EXISTS");
    } else {
        [fileManager copyItemAtPath:copyFrom toPath:[self dataFilePath] error:nil];
        NSLog(@"COPIED DB TO DOCUMENTS BECAUSE IT DIDNT EXIST: NEW INSTALL");
    }
    if (sqlite3_open([[self dataFilePath] UTF8String], &database) != SQLITE_OK) {
        sqlite3_close(database); NSAssert(0, @"Failed to open database");
        NSLog(@"FAILED TO OPEN DB");
    } else {
        if([fileManager fileExistsAtPath:[self dataFilePath]]) {
            //NSLog(@"DB PATH:");
            //NSLog([self dataFilePath]);
        }
    }
    return database;
}

+ (NSString *)dataFilePath { 
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documentsDirectory = [paths objectAtIndex:0]; 
    return [documentsDirectory stringByAppendingPathComponent:@"kanji_training.sqlite"];
}

I really can’t work it out! Can anyone help me?

Many thanks.

  • 1 1 Answer
  • 2 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-05-14T01:20:56+00:00Added an answer on May 14, 2026 at 1:20 am
    char *update = "UPDATE Kanji SET EF = ? WHERE Kanji = '?'";
    

    Replace it with

    char *update = "UPDATE Kanji SET EF = ? WHERE Kanji = ?";
    

    It’s already a string. You don’t need single quotes around that question mark.

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

Sidebar

Related Questions

We’ve found that the unit tests we’ve written for our C#/C++ code have really
I have some really complicated legacy code I've been working on that crashes when
We have some really old code that calls WebServices using behaviours (webservice.htc), and we
I'm having a really frustrating error trying to secure an ASP.NET application using the
What should i use to code Classic ASP under Linux. I have really tried
I have a really big database (running on PostgreSQL) containing a lot of tables
I have never really found the design view in Visual Studio useful when developing
I have a really long 3 column table. I would like to <table> <tr><td>Column1</td><td>Column2</td></tr>
Do I really have to learn Objective-C to develop solid Mac Apps? As Mac
I have a really simple search form with the following Label (Search) Textbox (fixed

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.