gpt4 book ai didi

swift - SQLite数据库错误: The FMDatabase is not open.

转载 作者:行者123 更新时间:2023-11-30 12:09:02 26 4
gpt4 key购买 nike

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

var instance = ModelManager()

class ModelManager: NSObject {

var database: FMDatabase? = nil
var database2: FMDatabase? = nil
var resultSet: FMResultSet!

class func getInstance(sqllite:String) -> ModelManager {
if(instance.database == nil){
instance.database = FMDatabase(path: Util.getPath(sqllite))
}
return instance
}
class func getInstance2(sqllite:String) -> ModelManager {
if(instance.database2 == nil){
instance.database2 = FMDatabase(path: Util.getPath(sqllite))
}
return instance
}

}

这是我收到错误的代码。

   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()
}

请给出这个问题的解决方案。发出查询后我并没有关闭数据库。这会导致 cpu 使用率超过 200。所以现在我正在关闭数据库。但我收到这个错误。感谢您的帮助。

最佳答案

我找到了这个问题的解决方案。我有关闭数据库的方法内部的方法。因为那个错误来了。感谢您的帮助。

关于swift - SQLite数据库错误: The FMDatabase <FMDatabase: 0x6080000a96c0> is not open.,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46292229/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com