FMDB SQLite question: row count of a query?

前端 未结 8 2033
别那么骄傲
别那么骄傲 2021-02-01 17:41

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

8条回答
  •  余生分开走
    2021-02-01 18:20

    The first one is also right but by using this method you can retrieve records and count using the same query , no headache to write another one. Just add count(*) as count to your query.

    You could always just run the proper SQL statement. I do something like:

    FMResultSet *rs = [database executeQuery:@"select count(*) as count from words"];
    [rs next];
    
    wordsThatExist = [rs intForColumn:@"count"];
    

    Setting up the SQL query may be quicker and cheaper then iterating.. I believe counts are cheap.

提交回复
热议问题