Search code examples
objective-csqlitefmdb

Iterate through a ResultSet outside of a Transaction?


I have some code that looks like this:

__block FMResultSet *s;
[databaseQueue inDatabase:^(FMDatabase * _Nonnull db) {
    s = [db executeQuery: @"SELECT * session;"];
}];

while ([s next]){
    //convert the row into a Session object.
    [databaseQueue inDatabase:^(FMDatabase * _Nonnull db) {
        [db executeUpdate:@"UPDATE session ...", arg1, arg2];
    }];
}

Is this okay? Or do I need to move the while loop inside the first inDatabase block?

I am using FMDB and objective C, but my guess is that something like this is standard across most database wrappers.


Solution

  • After some more testing I am able to answer my own question. I am getting a warning when I try something like what I outlined above:

    Warning: there is at least one open result set around after performing [FMDatabaseQueue inDatabase:]

    So I guess you can do it, because I did get results back. But at least fmdb, doesn't like the idea...