Unable to update database using asynchronous method

I am trying to update some values ​​in my database using an async task, but I get this error:

Values ​​not inserted. Error: SQL logic error or missing database

Here is the code I use to update db:

- (void)persistResponseData:(NSDictionary *)data database:(DataBaseHandler *)database completion:(void (^)(NSError *error))completion {

    NSDictionary *contentData = [data objectForKey:@"contentdata"];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{


        // Process Contents
        NSArray *contents = [contentData objectForKey:@"contents"];
        if (contents != nil) {
            [self storeData:contents inTable:@"contents" database:database withCustomIdentifier:nil];
        }

    });

    }

The error in this line of code with the error code EXC_BAD_ACCESS:

if (sqlite3_prepare_v2(_database, [query UTF8String], -1, &statement, nil)==SQLITE_OK)

which is called when I try to confirm whether a record exists or not, inside the storeData function.

If I remove the asynchronous part

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

then the code runs without any problems and the database is updated. Any idea how to solve this?

+4
source share

No one has answered this question yet.

See related questions:

5129
?
2817
?
2302
?
1256
?
1110
, ?
0

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


All Articles