iosswiftfmdb

FMDB / sqlite query problem with function


I am really new to swift and trying to understand ios programming. Basically I have a table where "id" and "fact" columns. id is primary key'd and here is the swift fuction I am trying to query the values

func getItemsFromRow(fact_cid: String) ->[FactsData]{
    var rowData: [FactsData]!
    let rawQ = "select * from facts where \(facts_id)=?"
    if (openDatabase()){
        do{
            let results = try database.executeQuery(rawQ, value(forKey: fact_cid))
            while results.next(){
                let currentFact = FactsData(factid: results.string(forColumn: facts_id), factsdata: results.string(forColumn: facts_fld))
                if rowData == nil {
                    rowData = [FactsData]()
                }
                rowData.append(currentFact)
            }
        }
    }
    return rowData
}

But this line gives me error

let results = try database.executeQuery(rawQ, value(forKey: fact_cid))

Error is

Cannot invoke 'executeQuery' with an argument list of type '(String, Any?)'

I am trying to pass the id as string. Not sure what I am doing wrong here.

Any help is much appreciated.


Solution

  • Change it to

    let results = try database.executeQuery(rawQ, values: [fact_cid])
    

    since the second parameter should be an array