简体   繁体   中英

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.

Change it to

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

since the second parameter should be an array

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM