jeudi 25 juin 2015

Having trouble with sqlite, fmdb and swift

I am really confused on how to use sqlite with Swift. My INSERT queries get executed without any errors but when I open the database the data that should have been added is not there. I am using the FMDB wrapper.

Here is my code:

let documentsFolder = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as! String

let path = documentsFolder.stringByAppendingPathComponent("currencylite.db")

let database = FMDatabase(path: path)

if !database.open() {
        println("Unable to open database")
        return

    } else {
        if database.open() {

let querySQL = "INSERT INTO currencyrates (baseccy, matchccy, rateccy, date) VALUES ('\(base)', '\(currency)', \(frate), '\(updtdate)')"
println(querySQL)                            

 database.executeQuery(querySQL, withArgumentsInArray: nil)
    }

println(querySQL) echoes INSERT INTO currencyrates (baseccy, matchccy, rateccy, date) VALUES ('AUD', 'ZAR', 9.3683, '2015-06-25')So I am pretty sure it doesn't come from the data by from the way I execute the query ...

Thank you for your help !

Aucun commentaire:

Enregistrer un commentaire