mercredi 2 mars 2016

GRBD Swift Sqlite

I'm using GRDB library for Swift Sqlite.

I create a class for connection:

import GRDB

var dbQueue: DatabaseQueue!

func setupDatabase() {

var config = Configuration()
config.readonly = true
config.foreignKeysEnabled = true
config.trace = { print($0)}



let databasePath = NSBundle.mainBundle().pathForResource("mydb", ofType: "sqlite")!

dbQueue = try! DatabaseQueue(path: databasePath, configuration:  config)

}

I call the class in the method:

func trovaCitta(luogoNascita: String)->CittaVO{

    let citta:CittaVO = CittaVO()


    dbQueue.inDatabase { db in

        for row in Row.fetch(db, "SELECT * FROM comune where cod_catastale='" + luogoNascita + "'") {
            citta.codIstat = row.value(named: "cod_istat")
            citta.nome = row.value(named: "nome")

                    citta.codProvincia = row.value(named: "cod_provincia")
                    citta.codValidita = row.value(named: "cod_validita")
                    citta.codCap = row.value(named: "cod_cap")
                    citta.codCatastale = row.value(named: "cod_catastale")
          //  print(citta)
        }

    }

    return citta
}

The app returns: fatal error: unexpectedly found nil while unwrapping an Optional value

0x1009f8764 <+36>: mov x4, x5 0x1009f8768 <+40>: bl 0x100a3add0 ; function signature specialization of Swift.(_fatalErrorMessage (Swift.StaticString, Swift.StaticString, Swift.StaticString, Swift.UInt) -> ()).(closure #2)

someone can give me suggestions? thanks

Aucun commentaire:

Enregistrer un commentaire