getting error as there is at least one open result set around after performing [FMDatabaseQueue inDatabase:]?

1.4k views Asked by At

In my app, there are multiple threads accessing the database. I have used the SQLite wrapper FMDB.

I heard that FMDB provide me us to handle multithreading via FMdatabaseQueue.

Due to that, I have used it like below:

@property (nonatomic, strong) FMDatabaseQueue *queue;

_queue = [[FMDatabaseQueue alloc] initWithPath:path];


- (BOOL)deleteSchoolDatabase:(NSString *)name anduserId:(NSString*)studentId {

    __block BOOL success = NO;

    [self.queue inDatabase:^(FMDatabase *db) {

        NSString *deleteStudentDBString = [NSString stringWithFormat:@"DELETE FROM user WHERE name=%@ AND studentId=%@",name,studentId,nil];

        success = [db executeQuery:deleteStudentDBString];

        NSAssert((![db hadError]), [db lastErrorMessage]);

        if ([db hadError]) {

            DebugLog(@"Error : %@", [db lastErrorMessage]);
            success = NO;
        }

    }];

    return success;
}

I Have used above format for fetching as well i.e

[self.queue inDatabase:^(FMDatabase *db) {
          //fetch details
}];

But now I am getting error as

Warning: there is at least one open result set around after performing [FMDatabaseQueue inDatabase:]
query: 'DELETE FROM user WHERE name='abc' AND studentId='12346';'

I have also checked out below links: https://groups.google.com/forum/#!topic/fmdb/oeu38he7UvQ

and I think I am closing the set once done. still, the error is occurring. and this is happening for one table only. In other table are able to delete data from Database.

Thanks in advance.

1

There are 1 answers

0
Nik On

I am able to solve my problem. I was using the wrong method to delete the data. We need to use "executeUpdate" for deleting the data. So, do check your query is right.

- (BOOL)deleteSchoolDatabase:(NSString *)name anduserId:(NSString*)studentId {

    __block BOOL success = NO;

    [self.queue inDatabase:^(FMDatabase *db) {

        NSString *deleteStudentDBString = [NSString stringWithFormat:@"DELETE FROM user WHERE name=%@ AND studentId=%@",name,studentId,nil];

        success = [db executeUpdate:deleteStudentDBString];

        NSAssert((![db hadError]), [db lastErrorMessage]);

        if ([db hadError]) {

            DebugLog(@"Error : %@", [db lastErrorMessage]);
            success = NO;
        }

    }];

    return success;
}

Thanks.