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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:29:17+00:00 2026-06-15T23:29:17+00:00

I have a database that has a student entity: create table student ( name

  • 0

I have a database that has a student entity:

create table student ( name varchar(20) not null,
                       surname varchar(20) not null,
                       studentId integer primary key );

In my app delegate when the application starts I load all the tuples from the database and display them to a table view.
When the app delegate receiver the applicationWillResignActive event it saves all the tuples to the database.It saves only the tuples that have been added, there isn’t the possibility to edit the tuples so that’s fine.
When the app delegate receives the applicationWillEnterForeground event it reads the tuples from the database.

The problem: This works only inside a single launch of the application.Let’s say that I launch the application through Xcode, then I enter I add an element and enter in background.Afterwards I reactivate the application, it goes in foreground, and it loads successfully all the tuples.
But at the next launch of the application (stopping it from lldb and launching it again) the tuples are the same as before the first launch.

I created a wrapper class for the student entity, named Student, with these properties:

@property (nonatomic, copy, readwrite) NSString* name;
@property (nonatomic, copy , readwrite) NSString* surname;
@property (nonatomic, strong, readwrite) NSNumber* studentId;
@property (nonatomic, readwrite, getter= isNew) BOOL new;

I check that the fields are not nil and that the entity integrity is not violated.
The only significative method that I use is this:

- (NSString*) sqlInsertionString;

It creates the string necessary to insert the tuple.Tested and works.

So that’s how I update the database:

- (void) updateStudents : (NSMutableArray*) students
{
    sqlite3* database;
    sqlite3_stmt* statement;
    BOOL needsFinalize=NO;
    if(!databasePath)
    {
        NSBundle* bundle=[NSBundle mainBundle];
        databasePath= [bundle pathForResource: @"test" ofType: @"db"];
    }
    if(sqlite3_open([databasePath UTF8String], &database)!=SQLITE_OK)
    {
        NSString* problem= [NSString stringWithFormat: @"%s",sqlite3_errmsg(database)];
        @throw [NSException exceptionWithName: @"Failed to open the database" reason: problem userInfo: nil];
    }
    for(Student * s in students)
    {
        if(s.isNew)
        {
            NSString* sqlString= [s sqlInsertionString];
            if(sqlite3_prepare_v2(database, [sqlString UTF8String], -1, &statement, NULL)!= SQLITE_OK)
            {
                @throw [NSException exceptionWithName: @"Problem performing the query" reason: @"Unknown" userInfo: nil];
            }
            if(sqlite3_step(statement)!=SQLITE_DONE)
            {
                @throw [NSException exceptionWithName: @"Problem performing the query" reason: @"Unknown" userInfo:nil];
            }
            sqlite3_reset(statement);
            needsFinalize=YES;
        }
    }
    if(needsFinalize && sqlite3_finalize(statement)!=SQLITE_OK)
    {
        @throw [NSException exceptionWithName: @"Failed to close the statement resource" reason: @"Unknown" userInfo:nil];
    }
    if(sqlite3_close(database)!= SQLITE_OK)
    {
        @throw [NSException exceptionWithName: @"Failed to close the database" reason: @"Unknown" userInfo: nil];
    }
}

But it doesn’t get really updated, only inside the application it appears to be updated, but the file always remains the same.

  • 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-15T23:29:19+00:00Added an answer on June 15, 2026 at 11:29 pm

    The problem is that you’re opening the database from the bundle. You can’t make (persistent) modifications to that. The standard solution is to check for the database in your Documents folder, if there, use it, if not, copy from bundle to Documents and then open the database from Documents.

    See Unable to connect SQLite Database in iOS

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

Sidebar

Related Questions

I have a database that has a table email_eml that stores 3 attributes name_eml,
I have a database that has node & nodetype tables. Nodes table NodeID ParentNodeID
I have a SQL database that has a table with a field set to
I have a database table that has a Unique Key constraint defined to avoid
I have a SQL database that has the following table: Table: PhoneRecords -------------- ID(identity
I have a database that has around 10k records and some of them contain
I have a database that has 16 tables, but only four are relevant to
I have a database that has the following columns: ------------------- id|domain|hit_count ------------------- And I
I have a mysql database that has text stored in it with non encoded
I have inherited a database that has a lot of cursors in it, and

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.