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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:41:48+00:00 2026-06-12T07:41:48+00:00

I created a SQLite database that currently has only one table. I connected it

  • 0

I created a SQLite database that currently has only one table. I connected it to Xcode, made the all required steps, and found a problem in writing my files.

My table has 5 items (primary key, name, birth date, college name, course name).

While saving my data, it says:

Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘Error while creating add statement. ‘library routine called out of sequence”

I set breakpoints and found where the problem is, but I just can’t solve it.

-(void)saveStudentInfo{

sqlite3_stmt *statement = NULL;


    const char *sql = "insert into studentInfo (name,collegeName,courseName) Values (?, ?, ?)";

    if (sqlite3_open("my_db_filename.db", &database) == SQLITE_OK)
    {
        //sqlite3_stmt *addStmt;

        if(sqlite3_prepare_v2(database, sql, -1, &addStmt, NULL) != SQLITE_OK)
        {
            NSAssert1(0, @"Error while creating add statement. '%s'", sqlite3_errmsg(database));
        } else {
            // do things with addStmt, call sqlite3_step
            sqlite3_bind_text(addStmt, 1, [studentName UTF8String], -1, SQLITE_TRANSIENT);
            sqlite3_bind_text(addStmt, 3, [studentCollegeName UTF8String], -1, SQLITE_TRANSIENT);
            sqlite3_bind_text(addStmt, 4, [studentCourseName UTF8String], -1, SQLITE_TRANSIENT);

            if(SQLITE_DONE != sqlite3_step(addStmt))
                NSAssert1(0, @"Error while inserting data. '%s'", sqlite3_errmsg(database));
            else
                studentID = sqlite3_last_insert_rowid(database);

            sqlite3_finalize(statement);
        }
        sqlite3_close(database);     
    }


if (sqlite3_step(statement)==SQLITE_DONE){
    UIAlertView *error = [[UIAlertView alloc]initWithTitle:@"Done" message:@"Files were added to database" delegate:self cancelButtonTitle:@"Close" otherButtonTitles:nil, nil];
    [error show];
}
else {
    UIAlertView *error = [[UIAlertView alloc]initWithTitle:@"Error" message:@"StudentOrganizer could not add database" delegate:self cancelButtonTitle:@"Close" otherButtonTitles:nil, nil];
    [error show];
}
  • 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-12T07:41:49+00:00Added an answer on June 12, 2026 at 7:41 am

    I think you forgot to open the database before calling sqlite3_prepare_v2.

    A good way to do it is like this:

    sqlite3* database;
    if (sqlite3_open("my_db_filename.db", &database) == SQLITE_OK)
    {
        sqlite3_stmt *addStmt;
    
        if(sqlite3_prepare_v2(database, sql, -1, &addStmt, NULL) != SQLITE_OK)
        {
            NSAssert1(0, @"Error while creating add statement. '%s'", sqlite3_errmsg(database));
        } else {
            // do things with addStmt, call sqlite3_step
            sqlite3_finalize(sqlStatement);
        }
        sqlite3_close(database);     
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently writing a java-class that wraps an SQLite database. This class has
I have made this code to open a database(created in SQLite browser) stored in
I currently have a closure table used for hierarchical data that has 5 million
I created a C++ application that updates a SQLite database. The application reads a
I have an app that uses an sqlite database. Currently I have a database
I currently have a system in which one rails 2.3.2 has a database with
I have a local sqlite server. The SQL database only contains a table called
Let's say that I have a SQLite database that I create in a separate
I have an app that creates a SQLite database ( with 24 records ),
I am building an app that creates and communicates with an SQLite database. However,

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.