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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:47:54+00:00 2026-05-28T03:47:54+00:00

I got this exc_bad_access problem in AppDelegate.m What I did and want is to

  • 0

I got this exc_bad_access problem in AppDelegate.m
What I did and want is to have multiple sql query. To avoid complexity, I did two blocks (it will have more) and both are querying different table from sql.

-(void)readDataFromDatabase {

    // Setup the database object
    sqlite3 *database;

    // Initialize the budgetobjects Array
    Part1Array = [[NSMutableArray alloc] init];

    // Open the database from the users filessytem
    if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {

        // Setup the SQL Statement and compile it for faster access
        const char *sqlStatement = "select * from part1TBL";
        sqlite3_stmt *compiledStatement;
        if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
            // Loop through the results and add them to the feeds array
            while(sqlite3_step(compiledStatement) == SQLITE_ROW) {


                // Read the data from the result row
                // You can add more rows based on your object
                NSString *Part1_Name = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)];
                NSString *Part1_Description = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)];
                // Create a new Restaurant with the data from the database
                Part1 *newPart1 = [[Part1 alloc] initWithName:Part1_Name description:Part1_Description];

                // Add the budgetobject to BudgetObjectsrantArray
                [Part1Array addObject:newPart1];

            }
        }

        // Release the compiled statement from memory
        sqlite3_finalize(compiledStatement);

    }
    sqlite3_close(database);


    // Setup the database object
    sqlite3 *database2;

    // Initialize the budgetobjects Array
    Part2Array = [[NSMutableArray alloc] init];

    // Open the database from the users filessytem
    if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {

        // Setup the SQL Statement and compile it for faster access
        const char *sqlStatement = "select * from part2TBL";
        sqlite3_stmt *compiledStatement;
        if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
            // Loop through the results and add them to the feeds array
            while(sqlite3_step(compiledStatement) == SQLITE_ROW) {


                // Read the data from the result row
                // You can add more rows based on your object
                NSString *Part2_Name = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)];
                NSString *Part2_Description = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)];
                // Create a new Restaurant with the data from the database
                Part2 *newPart2 = [[Part2 alloc] initWithName:Part2_Name description:Part2_Description];

                // Add the budgetobject to BudgetObjectsrantArray
                [Part2Array addObject:newPart2];

            }
        }

        // Release the compiled statement from memory
        sqlite3_finalize(compiledStatement);

    }
    sqlite3_close(database2);





}



@end

The exc_bad_access highlighted at the end where

sqlite3_close(database2);
  • 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-28T03:47:54+00:00Added an answer on May 28, 2026 at 3:47 am

    I’m not familiar with sqlite, but it looks like the issue with your code is that you’re never opening ‘database2’. Instead, you open ‘database’ twice, which looks like a typo.

    // Open the database from the users filessytem
    if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {

    ….

    sqlite3_close(database);

    …

    // Open the database from the users filessytem
    if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
    // <— This should be &database2
    …

    sqlite3_close(database2);

    EDIT: Please note Mat’s answer as well – there’s several places where you’re using database when you meant to use database2, and you might want to consider just reusing database, or extracting this functionality into a shared function if applicable.

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

Sidebar

Related Questions

Got this error on a big $_GET query in size ~9 000 symbols (they
I am new to cocos2d and suddenly got this EXC_BAD_ACCESS, I made a new
Today I got a EXC_BAD_ACCESS ,so I debug the code to solve the problem.
Suddenly I got EXC_BAD_ACCESS on this line: int retVal = UIApplicationMain(argc, argv, nil, nil);
I have this problem of my app crashing (only when press a certain UIButton)
I've got a strange problem here. I have a class that I'll call MainView
Coding in VB.Net Hi guys I've got this problem where I'm trying to assign
I've got some troubles with OCMock and UIView. I have sort of this code:
I have got this code which creates an image: NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
I have a little bit of a problem... I understand what a EXC_BAD_ACCESS error

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.