Sqlite数据库错误:FMDatabase <fmdatabase:0x6080000a96c0 =“”>未打开。

时间:2017-09-19 05:07:40

标签: swift fmdb

我收到此错误&#34; FMDatabase未打开&#34;。即使我在执行查询之前首先打开我的数据库。这是我用来打开数据库的数据库实例代码。

   func saveImageAudio(audioFile:String?,imageFile:String?,isImage:Bool){

    guard (instance.database?.open())! else {
        return
    }

    let fileName = isImage == true ? imageFile : audioFile
    var paramName = isImage == true ? "imageList" : "audioList"
    let countParam = isImage == true ? "imageCount" : "audioCount"
    let time = Util.DateTime()

    guard increaseLastNo(isImage: isImage) else {
        return
    }

    do {

        let FileArray = getImageAudiolist(isImagelist: isImage)

        var query = ""
        var values:[Any] = []

        if FileArray.count == 0 {
            query = "update RoomSectionDetails set \(paramName) = ?, \(countParam) = 1 ,modified_dtm = ? where  pda_guid = ? and roomName = ? and sectionID = ? and dead = ?"
            values = [fileName!,time,pda_guid,roomName,sectionId,0]
        }else{
            query = "update RoomSectionDetails set \(paramName) = \(paramName) || ?, \(countParam) = \(countParam) + 1, modified_dtm = ? where  pda_guid = ? and roomName = ? and sectionID = ? and dead = ?"
            values = [",\(fileName!)",time,pda_guid,roomName,sectionId,0]
        }

        try instance.database?.executeUpdate(query, values: values)

        paramName = isImage == true ? "lastImageNo" : "lastAudioNo"

        if !isImage {
            self.updateAudioDuration()
        }
    } catch  {
        print("Error while Saving Image Audio in DB")
    }
     instance.database?.close()
   }

}

这是我收到错误的代码。

($dompdf->getOptions()->setIsFontSubsettingEnabled(true);)

请为此问题提供解决方案。在解雇查询后,我无法关闭数据库。导致cpu使用超过200.所以现在我关闭了数据库。但我得到这个错误。谢谢你的帮助。

1 个答案:

答案 0 :(得分:0)

我找到了解决这个问题的方法。我在关闭数据库的方法里面有方法。因为那个错误即将到来。谢谢你的帮助。