FMDatabase/SQLite3使用的"打开的文件太多"问题

Jer*_*son 6 sqlite macos xcode fmdb

我在我的OSX App中使用了SQLite3的FMDatabase包装器.我在数据库中做了很多插入:

FMResultSet *results;
results= [db executeQuery:@"select count(*) from `items` where key = ?",[keyPath lowercaseString],nil];

while([results next])
{
    if([results unsignedLongLongIntForColumnIndex:0]>0){
        updateOperation=TRUE;
    }
}
[results close];

if(updateOperation){

    [db executeUpdate:@"update `items` set OSXsize=?,OSXOsize=?, OSXDate=?, UUID=?,sourceFile=?,tombStone=0,SandBoxBookMark=?,songname=?,albumartist=? where key=?",
     size,originalSize, convertedDate,UUID,sourcePath,bookmark,fileName,albumArtist,[keyPath lowercaseString] , nil];
}
else
{
    [db executeUpdate:@"insert into `items`(key,filepath, OSXsize, OSXOsize, OSXdate,UUID,sourceFile,tombStone,SandBoxBookMark,songname,albumartist) values(?,?,?,?,?,?,?,0,?,?,?)",
     [keyPath lowercaseString], dapPath, size,originalSize, convertedDate,UUID,sourcePath,bookmark,fileName,albumArtist, nil];
}
Run Code Online (Sandbox Code Playgroud)

我打开数据库一次,但是,当应用程序在活动监视器中进行时,我看到附加了4725个文件句柄:

/Users/userA/Library/Containers/com.map-pin.Dapper/Data/Library/Application Support/com.map-pin.Dapper/dapperright.sqlite
15
16
...
4724
4725
Run Code Online (Sandbox Code Playgroud)

Jif*_*ang 0

这是在多线程应用程序中吗?db每次更新/插入行时都会创建并打开一个实例吗?你有[db close];地方吗?

您测试过FMDatabaseQueue吗?