FMDB SQLite question: row count of a query?

Viewed 25785

does anyone know how to return the count of a query when using FMDB? If I executeQuery @"select count(*) from sometable were..." I get an empty FMResultSet back. How can I get the row count of the query? Do I need to do a query like "select * from sometable where.." and iterate through the result set? Or can I use useCount or whats the best way (in terms of performance) to do this?

Thanks!

8 Answers

updated for Swift 4 minor change in method parameter name

if let rs = db.executeQuery("SELECT COUNT(*) as Count FROM TABLE_NAME", withArgumentsIn: nil) {
while rs.next() {
    print("Total Records:", rs.int(forColumn: "Count"))
    }
}
Related