SQLite can't create database outside of "Application Support"

I have an application that takes XML data and converts it into database tables. It uses SQLite3 and SQLCipher. If I hard code the path to save the database to put it in my Application Support folder, it works perfectly -- creates the file (with [fm createFileAtPath: newPath contents: nil attributes: nil];) and then opens it with SQLite, it creates the tables and populates them, everything works as expected.

If, however, I allow the user to save the database in the location of their choice, say in Documents or Downloads, the application creates the file (with createFileAtPath) but then when SQLite tries to create the tables, it fails with the error "unable to open database file" and error code 14 (which is a generic "couldn't open database" error.) Looking in the save directory, there is now a zero bytes file in that location.

Everything that I've seen online indicates that this is a permissions/security issue, but no one seems to point to a solution -- I went so far as to put in code to run chmod on the database and the folder that it's in, even that didn't help.

Your input is very much appreciated!

I have an application that takes XML data and converts it into database tables.

Let’s start with same basics:

  • What platform are you working on? It sounds like macOS, but I want to be clear.

  • If it is macOS, is your app sandboxed?

  • Oh, and again presuming this is macOS, are you planning to deploy via the Mac App Store? Or using direct distribution via Developer ID?

  • Also, just in case it ends up mattering, which OS version and what Xcode version are you using?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Hi Quinn, long time no chat.

Yes, this is a MacOS application. The app in question is intended for internal use, though the same functionality will eventually exist in a publicly available app (which will probably be distributed to end users directly, though that's not my decision.) There is nothing checked in the App Sandbox section of Signing & Capabilities, and the folders listed there are all Read/Write.

OS is 13.6.3 and Xcode is 15.1

SQLite can't create database outside of "Application Support"
 
 
Q