Search code examples
iosswiftsqlitefmdb

FMDB check if empty method and move forward separation


In FMDB the next function (as in if a!.next {}) does both checking if there is another row and also moving forward if there is another row, can we do these things separately, like only check if there is another row?

I have read the documentation but there seems no such direct method.


Solution

  • The next method in FMDB is simply a wrapper around the sqlite3_step function. You may be used to separate functions for "advance the recordset's cursor" and the "EOF test" that you see in other environments, but this is just how SQLite does it.

    So, unfortunately, no, SQLite doesn't really have separate functions for "is there another row" and "retrieve the next row". It's one function, sqlite3_step, which is called by FMDB's next, that serves both purposes. See the SQLite C interface API for a complete list of the SQLite functions.

    Perhaps FMDB's use of a class called FMRecordSet invites this sort of confusion, but we have to remember that it's really just a thin wrapper for the SQLite C API. It is limited to the same functions inherent in that API.