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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:43:42+00:00 2026-06-16T02:43:42+00:00

I saw that I was getting code error 5 when I was trying to

  • 0

I saw that I was getting code error 5 when I was trying to close the SQLite database.
So I struggled to reset all the resource used.
I believe that this is the method where I don’t properly reset all the resources:

- (NSArray*) allObjects
{
    NSMutableArray* objects=[NSMutableArray new];
    // resource is an ivar of type sqlite3_stmt* , it has been initialized with   
    // sqlite3_prepare, a query where I select some rows of a table
    if(!resource)
    {
        return nil;
    }
    while(sqlite3_step(resource)== SQLITE_ROW)
    {
        NSMutableDictionary* object=[NSMutableDictionary new];
        int count= sqlite3_column_count(resource);
        for(int i=0; i<count; i++)
        {
            // I need to know the type and the name of all columns to build
            // a dictionary object.Later I'll optimize it doing this only at 
            // the first loop iteration.
            const char* key=sqlite3_column_name(resource, i);
            int type= sqlite3_column_type(resource, i);
            const unsigned char* text;
            double value;
            switch (type)
            {
                case SQLITE_TEXT:
                    text=sqlite3_column_text(resource, i);
                    [object setObject: [NSString stringWithFormat: @"%s",text] forKey: [NSString stringWithFormat: @"%s",key]];
                    break;
                case SQLITE_INTEGER:
                    value= sqlite3_column_int(resource, i);
                    [object setObject: @(value) forKey: [NSString stringWithFormat: @"%s",key]];
                    break;
                case SQLITE_FLOAT:
                    value= sqlite3_column_double(resource, i);
                    [object setObject: @(value) forKey: [NSString stringWithFormat: @"%s",key]];
                    break;
                case SQLITE_NULL:
                    [object setObject: [NSNull null] forKey: [NSString stringWithFormat: @"%s",key]];
                    break;
                default:
                    break;
            }
        }
        // sqlite3_reset(resource);  Point 1
        [objects addObject: object];
    }
    // sqlite3_reset(resource);  Point 2
    return objects;
}

So if I put sqlite3_reset(resource) at point 2 when I close the database I get error 5, if I put it at point 1 I go in an infinite loop.
I’m almost sure the problem is in this function,I am also doing other things with the database, so the error may be in other parts of the code, but that’s a lot of code.So if the problem isn’t here write it in the comment and I’ll post other “suspicious” part of code.

  • 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-16T02:43:43+00:00Added an answer on June 16, 2026 at 2:43 am

    You should put the “reset” at point #2. And then you should call sqlite3_finalize on the prepared statement when you don’t need it anymore at all. You should also set the ivar to nil after doing this.

    sqlite3_reset says you are ready to use the statement again. sqlite3_finalize says that you are completely done with the statement and its resources should be cleaned up.

    An error 5 is SQLITE_BUSY. IF the “finalize” doesn’t fix the problem, do some searching on causes of SQLITE_BUSY.

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

Sidebar

Related Questions

I'm simply not getting this to work. I saw that this network isn't for
I have the following html code: I saw that for Watir-webdriver the Watir::Image.file_size method
I am getting the EXC_BAD_ACCESS error when trying to set a value inside a
I saw this sample code in SO that was saying one practice is bad
I am getting an ambiguity error in OpenCV when I am trying to calculate
I'm getting a 'module object has no attribute ... error when trying to use
I saw that even by writing separate commands, we can combine two different types
I saw that the Alfresco Cloud edition has nice share/publish features: (source: alfresco.com )
I saw that to show a JOptionPane message dialog I need the shutdownHooks permition.
I saw that one of our tools uses a ConsoleAppender to System.err next to

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.