I have an app which makes thousands of individual inserts into a SQLite3 
database.
I use FMDB as a Cocoa wrapper for SQLite.

Sqlite v 3.18.0
FMDB v 2.6.2

What I am seeing is the app crash as a result of “too many files open”, however 
I believe I am opening the database file only once:

if (![db openWithFlags:SQLITE_OPEN_NOMUTEX | SQLITE_OPEN_READWRITE | 
SQLITE_OPEN_CREATE]) {
        NSLog(@"Could not open db.");
    }


In OSX, if I launch Activity Monitor , double-click my app and look at Open 
files and ports, I see a steadily increasing number of references to my .sqlite 
file

(I have trimmed the output here, but the numbers count up from 15 to 4725)

cwd
/Users/nparker/Library/Containers/com.map-pin.Dapper/Data
txt
/private/var/folders/0n/14xdqy691_jdjrntkjg349qc0000gn/T/AppTranslocation/87ADEFD1-5363-48A2-89EE-7090093B38A4/d/Dapper-4.app/Contents/MacOS/Dapper
txt
/System/Library/Frameworks/ServiceManagement.framework/Versions/A/ServiceManagement
txt
/Library/Frameworks/iTunesLibrary.framework/Versions/A/iTunesLibrary
txt
/usr/lib/libsqlite3.dylib
txt
/usr/lib/libSystem.B.dylib
txt
/System/Library/Frameworks/IOKit.framework/Versions/A/IOKit
txt
/usr/lib/system/libdispatch.dylib
txt
/usr/lib/system/libdyld.dylib
txt
/usr/lib/system/liblaunch.dylib
txt
/usr/lib/system/libmacho.dylib
txt
/usr/lib/system/libquarantine.dylib
txt
/usr/lib/system/libsystem_c.dylib
txt
/usr/lib/system/libsystem_configuration.dylib
txt
/usr/lib/system/libsystem_coreservices.dylib
txt
/usr/lib/system/libsystem_dnssd.dylib
txt
/usr/lib/system/libsystem_info.dylib
txt
/usr/lib/system/libsystem_kernel.dylib
txt
/usr/lib/system/libsystem_m.dylib
txt
/usr/lib/system/libsystem_malloc.dylib
txt
/usr/lib/system/libsystem_network.dylib
txt
/usr/lib/system/libsystem_networkextension.dylib
txt
/usr/lib/system/libsystem_platform.dylib
txt
/usr/lib/system/libsystem_pthread.dylib
txt
/usr/lib/system/libsystem_sandbox.dylib
txt
/usr/lib/system/libsystem_secinit.dylib
txt
/usr/lib/system/libsystem_symptoms.dylib
txt
/usr/lib/system/libsystem_trace.dylib
txt
/usr/lib/system/libxpc.dylib
txt
/usr/lib/system/libkxld.dylib
txt
/System/Library/Frameworks/CFNetwork.framework/Versions/A/CFNetwork
txt
/usr/lib/libnetwork.dylib
txt
/System/Library/Frameworks/CoreDisplay.framework/Versions/A/CoreDisplay
txt
/usr/share/icu/icudt57l.dat
txt
/private/var/db/mds/messages/501/se_SecurityMessages
txt
/Users/testuser/Library/Containers/com.map-pin.Dapper/Data/Library/Caches/com.map-pin.Dapper/Cache.db-shm
txt
/System/Library/CoreServices/SystemAppearance.bundle/Contents/Resources/VibrantLightAppearance.car
txt
/System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vImage.framework/Versions/A/Libraries/libCGInterfaces.dylib
txt
/System/Library/Fonts/SFNSText.ttf
txt
/System/Library/Frameworks/Security.framework/Versions/A/PlugIns/csparser.bundle/Contents/MacOS/csparser
txt
/System/Library/CoreServices/SystemAppearance.bundle/Contents/Resources/FunctionRowAppearance.car
txt
/System/Library/CoreServices/SystemAppearance.bundle/Contents/Resources/SystemAppearance.car
txt
/System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/HIToolbox.framework/Versions/A/Resources/Extras2.rsrc
txt
/System/Library/Keyboard 
Layouts/AppleKeyboardLayouts.bundle/Contents/Resources/AppleKeyboardLayouts-L.dat
txt
/usr/lib/dyld
txt
/System/Library/CoreServices/SystemAppearance.bundle/Contents/Resources/Assets.car
txt
/System/Library/Fonts/Helvetica.dfont
txt
/System/Library/Frameworks/OpenGL.framework/Versions/A/Resources/GLEngine.bundle/GLEngine
txt
/System/Library/Extensions/AppleIntelBDWGraphicsGLDriver.bundle/Contents/MacOS/AppleIntelBDWGraphicsGLDriver
txt
/System/Library/Frameworks/OpenGL.framework/Versions/A/Resources/GLRendererFloat.bundle/GLRendererFloat
txt
/private/var/folders/0n/14xdqy691_jdjrntkjg349qc0000gn/C/com.map-pin.Dapper/com.map-pin.Dapper/com.apple.metal/libraries.data
txt
/private/var/folders/0n/14xdqy691_jdjrntkjg349qc0000gn/C/com.map-pin.Dapper/com.map-pin.Dapper/com.apple.metal/Intel(R)
 Iris(TM) Graphics 6100/functions.data
txt
/System/Library/Extensions/AppleIntelBDWGraphicsMTLDriver.bundle/Contents/MacOS/AppleIntelBDWGraphicsMTLDriver
txt
/private/var/folders/0n/14xdqy691_jdjrntkjg349qc0000gn/0/com.apple.LaunchServices-175-v2.csstore
txt
/private/var/db/dyld/dyld_shared_cache_x86_64h
0
/dev/null
1
/dev/null
2
/dev/null
3
/System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/HIToolbox.framework/Versions/A/Resources/Extras2.rsrc
4
/System/Library/Frameworks/CoreImage.framework/ci_kernels.metallib
5
/Users/testuser/Library/Containers/com.map-pin.Dapper/Data/Library/Caches/com.map-pin.Dapper/Cache.db
6
/Users/testuser/Library/Containers/com.map-pin.Dapper/Data/Library/Caches/com.map-pin.Dapper/Cache.db-wal
7
/Users/testuser/Library/Containers/com.map-pin.Dapper/Data/Library/Caches/com.map-pin.Dapper/Cache.db-shm
8
9
/Users/testuser/Library/Containers/com.map-pin.Dapper/Data/Library/Application 
Support/com.map-pin.Dapper/dapperleft.sqlite
10
/private/var/folders/0n/14xdqy691_jdjrntkjg349qc0000gn/C/com.map-pin.Dapper/com.map-pin.Dapper/com.apple.metal/libraries.maps
11
/private/var/folders/0n/14xdqy691_jdjrntkjg349qc0000gn/C/com.map-pin.Dapper/com.map-pin.Dapper/com.apple.metal/libraries.data
12
/private/var/folders/0n/14xdqy691_jdjrntkjg349qc0000gn/C/com.map-pin.Dapper/com.map-pin.Dapper/com.apple.metal/Intel(R)
 Iris(TM) Graphics 6100/functions.maps
13
/private/var/folders/0n/14xdqy691_jdjrntkjg349qc0000gn/C/com.map-pin.Dapper/com.map-pin.Dapper/com.apple.metal/Intel(R)
 Iris(TM) Graphics 6100/functions.data
14
/Users/nparker/Library/Containers/com.map-pin.Dapper/Data/Library/Application 
Support/com.map-pin.Dapper/dapperright.sqlite
15
16
17
18
19
20
21
22
23
24
25
26
27
…
4725

My queries are simple:

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];
}

_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to