Database locked while updating data in background

I am working on an application where I have to use sqlite and there is a lot of data. I want to load data from the column "resident_status" of a table named "tblResident". It takes too much time to load the data of this column (resident_status) for more than 8 seconds, and other data takes only one second. While retrieving data from the "resident_status" column, if I click the button, it will give me a "query error" in another part, but if I press the button after 8 seconds, than that works fine.

Here is my code:

if(sqlite3_exec(database, insert_stmt, NULL, NULL, &error)==SQLITE_OK)
{
  NSLog(@"succeddd.....");
    IsValidate = true;
    if([self checkNetConnection])
    {
        [self UpdateServerWith_LocalDB];
        NSString *Key= [DefaultsValues getStringValueFromUserDefaults_ForKey: @"Key"];

        if([[DefaultsValues getStringValueFromUserDefaults_ForKey: @"LastAuthenticationStatus"] isEqualToString:@"false"]){
            UIAlertView *alert=[[UIAlertView alloc]initWithTitle:nil message:@"Your Access is Restrcited,Please contact us" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
            [alert show];
        }
    }
}
else{
    NSLog(@"query error");
    ErrorMsg = [NSString stringWithFormat:@"%s", error ];
    IsValidate = false;
}
+4
source share

Source: https://habr.com/ru/post/1650899/


All Articles