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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:33:10+00:00 2026-05-23T14:33:10+00:00

I have an app that allows you to add items to a list, (From

  • 0

I have an app that allows you to add items to a list, (From a tableview), when the user clicks on the add button next to the corresponding item, it calls the following +(void)addItem method. Everything works fine, but after heavy testing (60-70 back to back inserts causes it to return the SQL error code “Unable to open database file” and the app has to be restarted. Any ideas? Thanks!

+(void)addItem:(NSString *)dbPath{

NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];

NSString *oldTrip = [prefs objectForKey:@"selectedList"];

NSString *table = @"The Table";

NSString *name = [prefs objectForKey:@"SelectedAddItem"];    
NSString *countStr = @"1";
NSString *doneStr = @"No";
NSString *noteStr = @"None";
NSString *orderStr = @"15";


sqlite3 *database;


if (sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK) {

    const char *sqlStr = [[NSString stringWithFormat:@"Insert into '%@' Values (null,?,?,?,?,?,?)",oldTrip]UTF8String];        

    sqlite3_stmt *compiledStatement;


    if (sqlite3_prepare_v2(database, sqlStr, -1, &compiledStatement, NULL) == SQLITE_OK){

        sqlite3_bind_text(compiledStatement, 0,[oldTrip UTF8String], -1, SQLITE_TRANSIENT);
        sqlite3_bind_text(compiledStatement, 1,[name UTF8String], -1, SQLITE_TRANSIENT);
        sqlite3_bind_text(compiledStatement, 2,[table UTF8String], -1, SQLITE_TRANSIENT);
        sqlite3_bind_text(compiledStatement, 3,[countStr UTF8String], -1, SQLITE_TRANSIENT);
        sqlite3_bind_text(compiledStatement, 4,[doneStr UTF8String], -1, SQLITE_TRANSIENT);
        sqlite3_bind_text(compiledStatement, 5,[noteStr UTF8String], -1, SQLITE_TRANSIENT);
        sqlite3_bind_text(compiledStatement, 6,[orderStr UTF8String], -1, SQLITE_TRANSIENT);

    }

    if(sqlite3_step(compiledStatement) != SQLITE_DONE ) {


        NSString* messageString = [NSString stringWithFormat: @"%s\n\nPlease contact the developer if this error persists", sqlite3_errmsg(database)]; 

        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error inserting" message:messageString delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];


        [alert show];
        [alert release];

    } else {

        sqlite3_reset(compiledStatement);

        sqlite3_finalize(compiledStatement);
    }

}

sqlite3_close(database);

}

To get the DB Information, I use:

- (NSString *) getDBPath {

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
return [documentsDir stringByAppendingPathComponent:@"ListDatabase.sql"];
}
  • 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-05-23T14:33:11+00:00Added an answer on May 23, 2026 at 2:33 pm

    If it happens only under heavy load, you may want to try leaving the database file open rather than opening and closing it for every operation. I’m not very familiar with SQLite, but you may also be able to reuse the compiled statement just by resetting its bindings each time around (and you don’t need to call reset before finalize if you don’t intend to reuse the statement).

    Perhaps you can open and close your database in your view controller’s viewDidLoad and viewDidUnload methods?

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

Sidebar

Related Questions

I have an app that allows the user to choose a picture from their
I am writing an app that allows the user to select from a list
I have an app that allows the user to choose an image, at design
I have a small tab on an app that allows user to lookup a
I have an app that allows a user to use JQuery and Javascript to
I have used TimeSpan control in my windows app C# that allows the user
I have a small cakePHP app that allows for user's to login and be
I have an app that allows a user to login, based upon the users
I have a simple little email app that allows a user to pick certain
So, the app that I'm writing allows the user to upload a photo from

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.