lundi 1 juin 2015

Swift SQLite SQL Count

In a Swift IOS 8 project with SQLite I'm trying to get the number of rows in a table using the SQL COUNT function. From the examples I found in C I came with this code:

var nRows: Int32 = 0

func getNquestions() {
     let querySQL = "SELECT COUNT(*) from table"
     let results:FMResultSet? = myDatabase.executeQuery(querySQL,withArgumentsInArray: nil)
     if results?.next() == true {
        nRows = results?.intForColumnIndex(0) //STATEMENT GENERATING ERROR
        }
    }

After getting a type mismatch error I changed the definition of nRows to Int32 but I keep getting compilation errors (this time "Value of optional type 'Int32? not unwrapped."

Any clues?

Aucun commentaire:

Enregistrer un commentaire