FMDB SQLite question: row count of a query?

前端 未结 8 2028
别那么骄傲
别那么骄傲 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:37

    If you want to know the count of the rows before make something with the result, you can even do a simple query and ask for the results columnCount that give you the number of rows and you can save one query if you really want to make something with the resultSet

    FMResultSet *results = [database executeQuery:@"SELECT * from tableName"];
    int numberOfRows = [results columnCount];
    
    while ([results next]){
    ... do your stuff ...
    }
    

提交回复
热议问题