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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:17:20+00:00 2026-06-06T21:17:20+00:00

I am using the FMDatabase SQLite wrapper in Objective C and I have the

  • 0

I am using the FMDatabase SQLite wrapper in Objective C and I have the following issue:

I am running an XML parse and DB insert in a background thread for some content that the user does not have access to, however the user is able to interact with a UI and database from the section they are in.

The FMDatabase <FMDatabase: 0x17b7b0> is currently in use.

Randomly, I will get a “FMDatabase already in use” notification and the array will never be populated by the database. I was under the impression that the FMDatabase class would handle the query once it became free, but I have a:

while(contents.count < 1){
     sleep(1);
}

Hoping that once the database frees up, the array will be populated. I have also tried rerunning the array population script if the DB is busy but to no avail.

Sorry if this question is confusing, I am happy to clarify.

  • 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-06T21:17:22+00:00Added an answer on June 6, 2026 at 9:17 pm

    I experienced the same issue.

    I switched to FMDatabaseQueue for every database query/update I had to do. It works like a charm !

    Using performSelectorOnMainThread is a good idea but when it comes to actual coding it can be pretty tricky to pass your arguments and get the results for further use.

    EDIT : here is a little example

    -(void) updateTaskStateAsync:(NSNumber *)taskID withNewStatus:(NSNumber *)state andCompletionBlock:(void(^)(BOOL status))completionBlock{
    
        NSString *errInfo = [NSString stringWithFormat:@"taskID %d - state %d", [taskID intValue], [state intValue]];
    
        [queue inDatabase:^(FMDatabase *db) {
            BOOL r = [db executeUpdate:@"UPDATE tasks SET state=?, date_job_last_updated=? WHERE identifier=?", state, [NSDate dateWithTimeIntervalSinceNow:0], taskID];
            DB_DISPLAY_ERROR(errInfo); // convenient macro to log errors
    
            if(completionBlock)
                completionBlock(r);
        }];
    }
    
    -(BOOL) updateTaskStateSync:(NSNumber *)taskID withNewStatus:(NSNumber *)state {
    
        NSString *errInfo = [NSString stringWithFormat:@"taskID %d - state %d", [taskID intValue], [state intValue]];
        __block BOOL r = NO;
        __block BOOL ended = NO;
    
        [queue inDatabase:^(FMDatabase *db) {
            r = [db executeUpdate:@"UPDATE tasks SET state=?, date_job_last_updated=? WHERE identifier=?", state, [NSDate dateWithTimeIntervalSinceNow:0], taskID];
            DB_DISPLAY_ERROR(errInfo); // convenient macro to log errors
    
            ended = YES;
        }];
    
        NSCondition *cond = [[NSCondition alloc] init];
        [cond lock];
        while(!ended)
            [cond wait];
    
        [cond unlock];
    
        return r;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using FMDatabase as sqlite wrapper for my iOS app, there's one place where
Am new to SQLite using in iPhone. I have used google and got some
Using android 2.3.3, I have a background Service which has a socket connection. There's
I need to make a long running task in the background. I'm using OmniThreadLibrary
Using Java,I have to fetch multiple sets of values from an XML file to
Using Rails 3.2.0.rc2 and ruby 1.9.3p0 In app/views/requests/_form.html.erb I have the following code for
So here is the deal, I am using FMDB SQLite Wrapper for my DB
Using the Exiv2 library to write some exif tags to an image i'm running
Even though I rarely have problems with FMDatabase, I noticed some odd behavior today
I have an iPad app that is using a sqlite database using FMDB as

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.