Fuggly Fuggly - 1 year ago 366
Objective-C Question

FMDB SQLite question: row count of a query?

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?


Answer Source

Shorter code to accomplish the same thing:

NSUInteger count = [db intForQuery:@"SELECT COUNT(field) FROM table_name"];

Make sure to include the FMDatabaseAdditions.h header file to use intForQuery:.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download