FMDB SQLite question: row count of a query?

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

    try this. It works for me. Iterating all the records is not recommended.

    FMResultSet *rs = [db executeQuery:@"select count(FIELD) as cnt from TABLENAME"];
    while ([rs next]) {
        NSLog(@"Total Records :%d", [rs intForColumn:@"cnt"]);
    }
    

    May be you should check your Where clause.

    0 讨论(0)
  • 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 ...
    }
    
    0 讨论(0)
提交回复
热议问题