且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

跨多个线程使用不同文件的SQLite死锁

更新时间:2022-11-05 19:05:10

我的应用通过链接到动态库来使用sqlite.我从此处(撰写本文时为3.8.7.4)下载了最新的SQLite源合并.进入应用程序,一切开始正常工作.因此,也许这是3.8.5中的错误.显然,直接将源代码编译到应用程序中的是

My app was using sqlite by linking against the dynamic library. I downloaded the latest SQLite source amalgamation from here (3.8.7.4 as of writing) and compiled it right into the app, and everything started working. So perhaps it was a bug in 3.8.5. Apparently compiling the source into the app directly is the recommended way to use sqlite anyway.

我仍然不知道是什么原因引起的.我唯一能想到的是,这与我创建数据库文件的方式有关:我正在使用NSFileManager createFileAtPath创建一个空文件,然后将其与SQLITE_OPEN_CREATE一起传递给sqlite3_open_v2.标志参数.因此,它将数据库写入现有文件中,而不是在指定位置创建数据库文件.

I still don't know exactly what caused the issue. The only thing I can think of is that it's something to do with how I'm creating the database files: I'm creating an empty file using NSFileManager createFileAtPath and then passing it to sqlite3_open_v2 with SQLITE_OPEN_CREATE as part of the flags parameter. So it's writing a database into an existing file instead of creating a database file at the specified location.