FMDB SQLite question: row count of a query?

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

    Swift 2 Example

    This code snippet will print the count for you.

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

    If it did not work, a few suggestions:

    a) Look for a line in your project that says let database = or var database =. If you find one then change db to database
    b) Did you change the TABLE_NAME in the Select statement to whatever your table is called?

提交回复
热议问题